我已2个不同阵列合并两个不同的阵列基于相同的密钥
首先是
(int) 0 => [
'id' => (int) 1,
'file_name' => 'test',
'imported_by' => 'John',
'valid_to' => (float) 1767225600000
],
(int) 1 => [
'id' => (int) 2,
'file_name' => null,
'imported_by' => 'John',
'valid_to' => (float) 1767225600000
],
第二个是
(int) 0 => object(App\Model\Entity\Product) {
'id' => (int) 1,
'product_cat' => (int) 10,
'product_type' => (int) 1,
'average....
我必须第一个推入基于第二个相同的钥匙
它看起来像这个一样
(int) 0 => object(App\Model\Entity\Product) {
'id' => (int) 1,
'product_category_id' => (int) 10,
'product_vessel_id' => (int) 1,
'average' => test;
//content from first array
'file_name' => 'test',
'imported_by' => 'John',
'valid_to' => (float) 1767225600000
我试过 array_merge_recursive($ firstArray,$ secondArray);但平均增加对firstArray
你可能需要一个定制的合并功能 –
你是说你想投的第一个数组作为一个对象,并使用相同的键合并对象?或者,将第二个数组转换为数组,合并后将整个事物作为对象进行投射? – mickmackusa
我必须合并第一个数组到第二个(如果存在),如果不是我仍然需要第二个数组的数据...所以像推到数组的地方id(first_array)== id(second_array) – JohnWayne