我有一个类似这样的数组:
Array
(
Array
(
[ID] => 1
[parentcat_ID] => 0
),
Array
(
[ID] => 2
[parentcat_ID] => 0
),
Array
(
[ID] => 6
[parentcat_ID] => 1
),
Array
(
[ID] => 7
[parentcat_ID] => 1
),
Array
(
[ID] => 8
[parentcat_ID] => 6
),
Array
(
[ID] => 9
[parentcat_ID] => 1
),
Array
(
[ID] => 13
[parentcat_ID] => 7
),
Array
(
[ID] => 14
[parentcat_ID] => 8
)
)
但是我需要一个函数来递归地将每个项放入相关父数组中的’children’数组中.所以它看起来更像是这样的:
Array
(
Array
(
[ID] => 1
[parentcat_ID] => 0
[children] => Array (
Array
(
[ID] => 6
[parentcat_ID] => 1
[childen] => Array (
Array
(
[ID] => 8
[parentcat_ID] => 6
[children] => Array (
Array
(
[ID] => 14
[parentcat_ID] => 8
)
)
)
)
),
Array
(
[ID] => 7
[parentcat_ID] => 1
[children] => Array(
Array
(
[ID] => 13
[parentcat_ID] => 7
)
)
),
Array
(
[ID] => 9
[parentcat_ID] => 1
)
)
)
Array
(
[ID] => 2
[parentcat_ID] => 0
)
)
我希望这是有道理的!