私がこの配列を持っていると仮定します:
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
)
)
)
)
よろしくお願いします。ありがとう ;)