很抱歉这么长的描述,但我在一天多的时间里一直在努力合并多个多维关联数组。任何人都可以建议实现这一目标的优化方法。我想根据所需的结果创建 HTML 列表。请参阅当前列表的附件图片。但我想把孩子合并成共同的父母。
阵列 1:
Array
(
[cat_id] => 1
[parent_cat_id] => 0
[cat_name] => Collectables
[children] => Array
(
[cat_id] => 1335
[parent_cat_id] => 1
[cat_name] => Animal Collectables
[children] => Array
(
[cat_id] => 10811
[parent_cat_id] => 1335
[cat_name] => Bird Collectables
[children] => Array
(
[cat_id] => 37847
[parent_cat_id] => 10811
[cat_name] => Bluebird
)
)
)
)
阵列 2:
Array
(
[cat_id] => 1
[parent_cat_id] => 0
[cat_name] => Collectables
[children] => Array
(
[cat_id] => 1335
[parent_cat_id] => 1
[cat_name] => Animal Collectables
[children] => Array
(
[cat_id] => 10811
[parent_cat_id] => 1335
[cat_name] => Bird Collectables
[children] => Array
(
[cat_id] => 37848
[parent_cat_id] => 10811
[cat_name] => Hummingbird
)
)
)
)
我希望结果保持公共数组不变,并在同一级别上创建另一个子数组,如下所示。
Array
(
[cat_id] => 1
[parent_cat_id] => 0
[cat_name] => Collectables
[children] => Array
(
[cat_id] => 1335
[parent_cat_id] => 1
[cat_name] => Animal Collectables
[children] => Array
(
[cat_id] => 10811
[parent_cat_id] => 1335
[cat_name] => Bird Collectables
[children] => Array
(
[0] => Array(
[cat_id] => 37847
[parent_cat_id] => 10811
[cat_name] => Bluebird
)
[1] => Array(
[cat_id] => 37848
[parent_cat_id] => 10811
[cat_name] => Hummingbird
)
)
)
)
)
[在此处输入图片描述][1]
[1]:当前列表:https ://i.stack.imgur.com/p4F0X.png