I have been experimenting with the Modified Pre-Order Tree Traversal Pattern, my test case code is returning the results as expected however I am having trouble converting the 2D array into a multi-dimensional array to present it.
Here is an example of a 3 level menu result, I need to convert this into a multi-dimensional array so that I can iterate it in TAL:
Array
(
[0] => Array
(
[CategoryID] => 1
[ParentID] => 0
[CategoryName] => Default Parent
[lt] => 1
[rt] => 14
[tree_depth] => 1
)
[1] => Array
(
[CategoryID] => 8
[ParentID] => 1
[CategoryName] => SysAdmin
[lt] => 2
[rt] => 7
[tree_depth] => 2
)
[2] => Array
(
[CategoryID] => 2
[ParentID] => 8
[CategoryName] => Linux
[lt] => 3
[rt] => 4
[tree_depth] => 3
)
[3] => Array
(
[CategoryID] => 3
[ParentID] => 8
[CategoryName] => Windows
[lt] => 5
[rt] => 6
[tree_depth] => 3
)
[4] => Array
(
[CategoryID] => 5
[ParentID] => 1
[CategoryName] => Code
[lt] => 8
[rt] => 13
[tree_depth] => 2
)
[5] => Array
(
[CategoryID] => 6
[ParentID] => 5
[CategoryName] => PHP
[lt] => 9
[rt] => 10
[tree_depth] => 3
)
[6] => Array
(
[CategoryID] => 7
[ParentID] => 5
[CategoryName] => Perl
[lt] => 11
[rt] => 12
[tree_depth] => 3
)
)
I need to structure the data so that every parent has a 'Children' key which is an array of arrays repeated, with no limitation on the amount of children a parent/child/grandchild can have, the tree_depth key is worked out automatically by the DBMS, so I simply need to alter the structure of the array.
Any pointers greatly appreciated, I have played with usort() and array_walk_recursive to no avail.
Thanks in advance