I have two arrays $a and $b
$a = [
'0' => [
'name'=>'Apple',
'id' => 1
],
'1' => [
'name'=>'Banana',
'id' => 2
],
'2' => [
'name' => 'orange',
'id' => 3
]
];
AND
$b = [
'0' => [
'price'=> 20,
'a_id' => 2
],
'1' => [
'price'=> 10,
'a_id' => 3
],
'3' => [
'price'=> 30,
'a_id' => 1
]
];
I am trying to create another array with mapping with id(array $a), a_id (array $b), where my output will looks like:
$a = [
'0' => [
'id' => 1
'name'=>'Apple',
'price' => 30
],
'1' => [
'id' => 2
'name'=>'Banana',
'price' => 20
],
'2' => [
'id' => 3
'name' => 'orange',
'price' => 10
]
];
I have tried by array map
$combined = array_map(null,$a,$b);
But this result is not my desire result. How can I map my 1st array with 2nd array related by $a['id'] = $b['a_id']
?