<?php $arr1 = [ [ 'id' => 1, 'name' => 'John', 'email' => 'j@mail.com' ], [ 'id' => 2, 'name' => 'Jane', 'email' => 'jane@mail.com' ] ]; $arr2 = [ [ 'id' => 1, 'email' => 'john@yahoo.com' ], [ 'id' => 2, 'email' => 'jane@yahoo.com' ], [ 'id' => 2, 'email' => 'jane.doe@hotmail.com' ], ]; foreach ($arr2 as ['id' => $id, 'email' => $lookup[$id][]]); foreach ($arr1 as ['id' => $id, 'email' => &$email]) { $email = array_merge((array) $email, $lookup[$id] ?? []); } var_export($arr1);
You have javascript disabled. You will not be able to edit any code.