[英]add php array element to an array how has same key and value
I have an array like this how had same gtin:我有一个像这样的数组如何有相同的gtin:
Array
(
[0]
(
[status] => ERROR
[message] => 'message error'
[gtin] => 03661733003170
)
[1]
(
[status] => SUCCESS
[message] =>
[gtin] => 03661985096630
)
)
and another array like this:和另一个这样的数组:
Array
(
[0] => Array
(
[e_id] => 219
[v_id] => 20
[gtin] => 03661733003170
)
[1] => Array
(
[e_id] => 217
[v_id] => 15
[gtin] => 03661985096630
)
)
I want to combine this two array in one array how has the same gtin like this I have try lot of php function but nothing resold my problem:我想将这两个数组组合在一个数组中如何具有相同的 gtin 像这样我尝试了很多 php function 但没有转售我的问题:
Array
(
[03661733003170]
(
[status] => ERROR
[message] => 'message error'
[e_id] => 219,
[v_id] => 20
)
[03661985096630]
(
[status] => SUCCESS
[message] =>
[evt_id] => 217,
[evl_id] => 15
)
)
thank for help谢谢帮助
Assuming that all keys are numeric and iteritable and that both arrays are of equal length, a simple loop with array_merge() is probably your best bet.假设所有键都是数字且可迭代的,并且 arrays 的长度相同,那么使用array_merge()的简单循环可能是您最好的选择。
$myarray1 = ....
$myarray2 = ....
$resultarray = array();
for ($i = 0; $i == sizeof($myarray1); $i++) {
$resultarray[$i] = array_merge($myarray1[$i], $myarray2[$i]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.