[英]How to merge 4 different keys and values arrays in PHP?
It seems to be a common question but I couldn't find any help... 这似乎是一个常见的问题,但我找不到任何帮助...
I need to merge 4 arrays with different keys and values. 我需要合并具有不同键和值的4个数组。 So there are my 4 different arrays :
所以我有4个不同的数组:
array(7) {
["id"]=>
string(2) "32"
["title"]=>
string(7) "Blettes"
["product_type_id"]=>
string(2) "43"
["quantity"]=>
string(4) "1.00"
["price"]=>
string(4) "2.80"
["created_at"]=>
string(19) "2011-09-03 11:31:35"
["proposition_vente"]=>
string(1) "4"
}
array(4) {
["id"]=>
string(2) "32"
["achat"]=>
string(2) "47"
["total_price"]=>
string(18) "131.59999999999994"
["total_vat"]=>
string(18) "6.8619999999999965"
}
array(2) {
["id"]=>
string(2) "32"
["exposition"]=>
string(2) "46"
}
array(3) {
["id"]=>
string(2) "32"
["sale_queue_id"]=>
string(3) "163"
["exposition"]=>
string(2) "56"
}
Into this one: 进入这一个:
array(7) {
["id"]=>
string(2) "32"
["title"]=>
string(7) "Blettes"
["product_type_id"]=>
string(2) "43"
["quantity"]=>
string(4) "1.00"
["price"]=>
string(4) "2.80"
["created_at"]=>
string(19) "2011-09-03 11:31:35"
["proposition_vente"]=>
string(1) "4"
["achat"]=>
string(2) "47"
["total_price"]=>
string(18) "131.5"
["total_vat"]=>
string(18) "6.86"
["exposition"]=>
string(2) "46"
["sale_queue_id"]=>
string(3) "163"
["exposition"]=>
string(2) "56"
}
I know I have to use the id to correctly merge them. 我知道我必须使用ID来正确合并它们。 I tried to use a combination of foreach() and array_merge() without success.
我尝试使用foreach()和array_merge()的组合,但未成功。
Any help is welcome :) 欢迎任何帮助:)
$result = array_merge($arr1, $arr2, $arr3, $arr4) should work.
You can try this too: 您也可以尝试以下方法:
$result = array();
$source = array($arr1, $arr2, $arr3, $arr4);
foreach ($source as $a) {
$result = array_merge($result, $a);
}
I figure it out with this: 我想出了这个:
foreach ($totalProposition as $key => $value) {
$test[$key]=array_merge($totalProposition[$key], $totalAchat[$key], $uniqueSale2[$key], $exposition2[$key]);
}
Thank you for your help : ) 谢谢您的帮助 : )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.