我在从文件夹数组创建类似文件夹结构的数组时遇到问题。
这是函数接收的数组
Array
(
[0] => Array
(
[id] => 6
[name] => 2011
[parent_folder] => 1
)
[1] => Array
(
[id] => 5
[name] => 2012
[parent_folder] => 1
)
[2] => Array
(
[id] => 7
[name] => April
[parent_folder] => 6
)
[3] => Array
(
[id] => 2
[name] => Folder2
[parent_folder] =>
)
[4] => Array
(
[id] => 1
[name] => Folder1
[parent_folder] =>
)
)
输出应该是一个数组,其中子文件夹作为数组存储在其 partent_folder 数组中的键“内容”下
Array
(
[0] => Array
(
[id] => 2
[name] => Folder2
[parent_folder] =>
)
[1] => Array
(
[id] => 1
[name] => Folder1
[parent_folder] =>
[content] => Array
(
[0] => Array
(
[id] => 6
[name] => 2011
[parent_folder] => 1
[content] => Array
(
[0] => Array
(
[id] => 7
[name] => April
[parent_folder] => 6
)
)
)
[1] => Array
(
[id] => 5
[name] => 2012
[parent_folder] => 1
)
)
)
)
我试过了,但无法让它工作。必须有一种递归方式来重新排列数组。有人可以帮忙吗?将不胜感激!