Skip to content
Advertisement

Format simpe array in multidimensional

I have a simple array in PHP like this :

JavaScript

I want to convert this array in multidimensional width underscore as separator :

JavaScript

I can do this with the following uggly code :

JavaScript

How can I do this with a pretty function ? Thanks for reply

Advertisement

Answer

It’s pretty easy to achieve by iterating and adding branch by branch to the resulting array. Something like this.

JavaScript

The result array would look the following way.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement