3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [0]=> array(3) { ["id"]=> int(1) ["name"]=> string(5) "Peter" ["surname"]=> string(6) "Newman" } [1]=> array(3) { ["id"]=> int(2) ["name"]=> string(4) "John" ["surname"]=> string(4) "Cena" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
123.89 ms | 406 KiB | 5 Q