【发布时间】:2019-05-25 03:01:27
【问题描述】:
我有 2 个数组,如下所示:
$array1 = [
'0' => [
'no_invoice' => 'INV0001',
'product_code' => '1111111',
],
'1' => [
'no_invoice' => 'INV0001',
'product_code' => '1111112',
]
];
$array2 = [
'0' => [
'product_code' => '1111112',
'free_valie' => 839,
'count' => 1240
],
];
是否可以将上面的数组组合成这样:
Array(
[0] => Array
(
'no_invoice' => 'INV0001',
'product_code' => '1111111',
)
[1] => Array
(
'no_invoice' => 'INV0001',
'product_code' => '1111112',
'free_valie' => 839,
'count' => 1240
)
)
所以,如果数组有相同的产品代码,那么它将像上面的例子一样加入。
我已经尝试过使用数组合并,array_merge($array1, $array2);
但是结果是这样的:
Array(
[0] => Array
(
'no_invoice' => 'INV0001',
'product_code' => '1111111',
)
[1] => Array
(
'no_invoice' => 'INV0001',
'product_code' => '1111112',
)
[2] => Array
(
'product_code' => '1111112',
'free_valie' => 839,
'count' => 1240
)
)
【问题讨论】:
-
问题中无需添加“已解决”;接受一个答案就是这样标记它。
-
好的先生,.....
标签: php arrays yii2 frameworks