php - Add a new dimension to a multidimensional array without having the full path -


If my title is confusing then sorry I have categories which look like this:

 < Code> id, name, parent 1, cat 1, 2, cat 1_1, 1 3, cat 1_2, 1 4, cat 2, 5, cat 2_1, 4 6, cat 2_1_1, 5  

I am trying to get it in a multi-dimensional array so that the tree of the tree is available in the right format for the purposes displayed.

I am writing recursive function (inside orbit), which writes each class of class in a square variable. My problem is that once I go down from the second level, then I I lose the ability to refer to Class V to make children of the class.

I can get the representation of the string of the array path, but there is a way that I can evaluate that to reach the correct level of the array ...

For example:

  $ path_string = "[4] ['children'] [5] ['children']";  

Is there a function that I then get $ cat_path = $ cats $ Path_string is the $ cat_path pointing to the correct level of the array.

Sorry if this is all a bit confusing. Alternatively, if someone has a better way of obtaining data in a right multi-dimensional array (as above in the table table above), please let me know!

Thanks

You can create a function that can path your path For example:

  get function ($ array, $ path) {foreach ($ path $ path member) {if (! Array_key_exists ($ arrays, $ pathMember)) {return null; } $ Array = $ array [$ pathMember]; If (Array_key_exists ($ array, 'kids')) {// or throw returns; } $ Array = $ array ['children']; } $ Array returned; } $ Descended = descend ($ ranges, array (4, 5));  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -