I have two arrays:
$arr1 = [
[
'id' => 1,
'name' => 'John',
'email' => '[email protected]'
],
[
'id' => 2,
'name' => 'Jane',
'email' => '[email protected]'
]
];
And the second array:
$arr2 = [
[
'id' => 1,
'email' => '[email protected]'
],
[
'id' => 2,
'email' => '[email protected]'
],
[
'id' => 2,
'email' => '[email protected]'
],
];
I would like to add all values with the same 'id' from the second array to the first array. The result I expect would be:
$arr3 = [
[
'id' => 1,
'name' => 'John',
'email' => ['[email protected]', '[email protected]']
],
[
'id' => 2,
'name' => 'Jane',
'email' => ['[email protected]', '[email protected]', '[email protected]']
]
];