很抱歉这么长的描述,但我已经为合并多个多维关联数组苦苦挣扎了一天多了。任何人都可以建议实现这一目标的优化方法。我想根据所需的结果创建 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]:当前列表:https ://i.stack.imgur.com/p4F0X.png
胡说叔叔