3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // result from db $recordset1 = [ [ 'id' => 1337, 'name' => 'Foo', 'age' => '40', 'sex' => 'yes please', ], [ 'id' => 1347, 'name' => 'Foo', 'age' => '40', 'sex' => 'yes please', ], ]; // this I want $recordset = [ 1337 => [ 'name' => 'Foo', 'age' => '40', 'sex' => 'yes please', ], 1347 => [ 'name' => 'Foo', 'age' => '40', 'sex' => 'yes please', ], ]; $result = array_map('array_diff_key', array_column($recordset1, null, 'id'), array_fill(0, count($recordset1), ['id'=>1])); var_dump($result);
Output for 5.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(2) { [0]=> array(3) { ["name"]=> string(3) "Foo" ["age"]=> string(2) "40" ["sex"]=> string(10) "yes please" } [1]=> array(3) { ["name"]=> string(3) "Foo" ["age"]=> string(2) "40" ["sex"]=> string(10) "yes please" } }
Output for 5.4.0 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/H4nu0 on line 33
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/H4nu0 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/H4nu0 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/H4nu0 on line 4
Process exited with code 255.