suppose i have this array:
Array
(
[0] => Array
(
[name] => ELECTRONICS
[depth] => 0
)
[1] => Array
(
[name] => TELEVISIONS
[depth] => 1
)
[2] => Array
(
[name] => TUBE
[depth] => 2
)
[3] => Array
(
[name] => LCD
[depth] => 2
)
[4] => Array
(
[name] => PLASMA
[depth] => 2
)
[5] => Array
(
[name] => PORTABLE ELECTRONICS
[depth] => 1
)
)
i want it to be converted into a multi-dimensional array such that immediate elements with a depth higher than the previous element will go inside the previous element with the key "children". like this:
Array
(
[0] => Array
(
[name] => ELECTRONICS
[depth] => 0
[children] => Array
(
[0] => Array
(
[name] => TELEVISIONS
[depth] => 1
[children] => Array
(
[0] => Array
(
[name] => TUBE
[depth] => 2
)
[1] => Array
(
[name] => LCD
[depth] => 2
)
[2] => Array
(
[name] => PLASMA
[depth] => 2
)
)
)
[1] => Array
(
[name] => PORTABLE ELECTRONICS
[depth] => 1
)
)
)
)
would greatly appreciate your help. thanks ;)