假设我有这个数组:
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
)
)
我希望将其转换为多维数组,以便深度高于前一个元素的直接元素将进入前一个元素的内部,键为“children”。像这样:
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
)
)
)
)
非常感谢您的帮助。谢谢 ;)