Possible Duplicate:
Recursive function to generate multidimensional array from database result
Consider the following array.
Array
(
[0] => Array
(
[Parent_ID] => 0
[Child_ID] => 0
[0] => string:val
)
[1] => Array
(
[Parent_ID] => 0
[Child_ID] => 1
[0] => string:val
)
[2] => Array
(
[Parent_ID] => 1
[Child_ID] => 2
[0] => string:val
)
[3] => Array
(
[Parent_ID] => 0
[Child_ID] => 3
[0] => string:val
)
I need to get this into something like the following.
Array
(
[0] => Array
(
[Parent_ID] => 0
[Child_ID] => 0
[0] => string:val
)
[1] => Array
(
[Parent_ID] => 0
[Child_ID] => 1
[0] => string:val
[2] => Array
(
[Parent_ID] => 1
[Child_ID] => 2
[0] => string:val
)
)
[3] => Array
(
[Parent_ID] => 0
[Child_ID] => 3
[0] => string:val
)
Further to that, Children can also have unlimited children. And not every index will have the same amount of keys and values. But all will have a parent and child key/value.
Iv'e tried numerous solutions from here and elsewhere and just cant seem to get it right.