3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ary1 = array( array( 'sn' => '123', 'name' => 'whatever', ), array( 'sn' => '234', 'name' => 'whatever', ), ); $ary2 = array( array( 'sn' => '123', 'gender' => 'male', ), array( 'sn' => '234', 'gender' => 'female', ), ); $res = []; foreach (array_merge($ary1, $ary2) as $a) { $res[$a['sn']] = array_merge($res[$a['sn']], $a) ?? $a; } var_dump($res);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined array key 123 in /in/1SE0o on line 27 Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given in /in/1SE0o:27 Stack trace: #0 /in/1SE0o(27): array_merge(NULL, Array) #1 {main} thrown in /in/1SE0o on line 27
Process exited with code 255.

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:
54.42 ms | 401 KiB | 8 Q