3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = array( array("id" => "1","name"=>"John"), array("id" => "2","name"=>"Peter"), array("id" => "3","name"=>"Tom"), array("id" => "12","name"=>"Astro") ); $array2 = array( array("id" => "1","second_name"=>"Lim"), array("id" => "2","second_name"=>"Parker"), array("id" => "3","second_name"=>"PHP") ); $result = array_column($array1, null, 'id'); foreach ($array2 as $row) { $result[$row['id']]['second_name'] = $row['second_name']; } var_export(array_values($result));

preferences:
33.65 ms | 406 KiB | 5 Q