<?php $arr1 = [ 0 => [ 'id' => 1, 'name' => 'Peter', ], 1 => [ 'id' => 2, 'name' => 'John', ] ]; $arr2 = [ 0 => [ 'id' => 1, 'surname' => 'Newman', ], 1 => [ 'id' => 2, 'surname' => 'Cena', ] ]; $finalArr = array_map(function($x) use ($arr2) { foreach($arr2 as $b) { if ($x["id"] === $b["id"]) { return array_merge($x, $b); } } return $x; }, $arr1); var_dump($finalArr);
You have javascript disabled. You will not be able to edit any code.