3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on QNA7D
Output for 7.0.0 - 7.2.0
array(2) { [123]=> array(3) { ["sn"]=> string(3) "123" ["name"]=> string(8) "whatever" ["gender"]=> string(4) "male" } [234]=> array(3) { ["sn"]=> string(3) "234" ["name"]=> string(8) "whatever" ["gender"]=> string(6) "female" } }
Output for 5.4.10 - 5.6.28
Parse error: syntax error, unexpected '?' in /in/5dIdO on line 27
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/5dIdO on line 25
Process exited with code 255.