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']] = (count($res[$a['sn']])) ? array_merge($res[$a['sn']], $a) : $a; } var_dump($res);
based on 1SE0o
Output for 7.2.0
Notice: Undefined offset: 123 in /in/76BuQ on line 27 Warning: count(): Parameter must be an array or an object that implements Countable in /in/76BuQ on line 27 Notice: Undefined offset: 234 in /in/76BuQ on line 27 Warning: count(): Parameter must be an array or an object that implements Countable in /in/76BuQ on line 27 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 - 7.1.10
Notice: Undefined offset: 123 in /in/76BuQ on line 27 Notice: Undefined offset: 234 in /in/76BuQ on line 27 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.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/76BuQ on line 25
Process exited with code 255.