在特定键上合并两个多维数组
本文介绍了在特定键上合并两个多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下数组:
第二个:
所需的输出是:
我已经设法将这些数组与简单地合并:
I have managed to merge these arrays with simply:
但是输出没有正确组合:
But the output is not combined correctly:
问题是我想在相同的 id
上合并这些数组.所需的输出排序应与第一个数组中的排序相同.
The problem is I would like to merge these arrays on the same id
.
Desired output sorting should be same as in the first array.
我怎样才能做到这一点?非常感谢任何帮助.
How can I achieve this? Any help is much appreciated.
推荐答案
你可以做一个嵌套循环并检查 id
值是否匹配,然后将 title
添加到$first
(或 name
到 $second
)
You can just do a nested loop and check if the id
values match, then add title
to $first
(or name
to $second
)
这篇关于在特定键上合并两个多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!