脚本宝典收集整理的这篇文章主要介绍了php – 合并两个多维关联数组,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试合并model_data和entry_data中的相应子数组以获取desired_result.然后,我将遍历desired_result并将值打印到模板中.
非常感谢任何帮助.
model_data
array(2) { [0]=> array(2) { ["entry_id"]=> string(3) "192" ["field_id_49"]=> string(10) "Model Name" } [1]=> array(2) { ["entry_id"]=> string(3) "193" ["field_id_49"]=> string(5) "Mn123" } }
entry_data
array(2) { [0]=> array(2) { ["uri"]=> string(24) "/PRoducts/product-tITle/" ["title"]=> string(13) "Product Title" } [1]=> array(2) { ["uri"]=> string(22) "/products/lorem-ipsum/" ["title"]=> string(11) "Lorem Ipsum" } }
desired_result
array(2) { [0]=> array(4) { ["entry_id"]=> string(3) "192" ["field_id_49"]=> string(10) "Model Name" ["uri"]=> string(24) "/products/product-title/" ["title"]=> string(13) "Product Title" } [1]=> array(4) { ["entry_id"]=> string(3) "193" ["field_id_49"]=> string(5) "MN123" ["uri"]=> string(22) "/products/lorem-ipsum/" ["title"]=> string(11) "Lorem Ipsum" } }
foreach($model_data as $key => $value){ $result[$key] = array_merge($entry_data[$key],$model_data[$key]); }
以上是脚本宝典为你收集整理的php – 合并两个多维关联数组全部内容,希望文章能够帮你解决php – 合并两个多维关联数组所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。