I have following 2 arrays:
$arr1 = [
0 => [
'id' => 1,
'name' => 'Peter',
],
1 => [
'id' => 2,
'name' => 'John',
]
]
$arr2 = [
0 => [
'id' => 1,
'surname' => 'Newman',
],
1 => [
'id' => 2,
'surname' => 'Cena',
]
]
What I want to do is merge these arrays referencing on the same key. In this case I would like to merge them where the id
is matching. So the output I would expect would be:
$finalArr = [
0 => [
'id' => 1,
'name' => 'Peter',
'surname' => 'Newman',
],
1 => [
'id' => 2,
'name' => 'John',
'surname' => 'Cena',
]
]
I am using laravel but the language should not matter too much. I would like to use collections
if possible.