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_column($recordset, null, 'id'), function($record){ return array_diff_key($record, ['id'=>1]); }); var_dump($result);
Output for 5.5.0 - 7.1.0
Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /in/lKHtg on line 33 NULL
Output for 5.4.0 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/lKHtg 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/lKHtg 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/lKHtg on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/lKHtg on line 4
Process exited with code 255.