合并两个多维关联数组 [英] Merging two multidimensional associative arrays
本文介绍了合并两个多维关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在追逐自己的尾巴,试图将两个不同查询的结果结合在一起以输出到模板中.
I'm chasing my tail trying to combine the results of two different queries to output in a template.
我正在尝试将model_data和entry_data中的相应子数组合并以获取期望的结果.然后,我将遍历desirable_result,然后将值打印到模板中.
I'm trying to merge the corresponding sub-arrays in model_data and entry_data to get desired_result. I will then iterate over desired_result and print values into the template.
我们非常感谢您的协助.
Any assistance is greatly appreciated.
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"
}
}
输入数据
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]);
}
这篇关于合并两个多维关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文