3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Examples 1 & 2 from http://nl3.php.net/array_column $records = array( 4 => array( 'id' => 2135, 'first_name' => 'John', 'last_name' => 'Doe', ), 8 => array( 'id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith', ), 2 => array( 'id' => 5342, 'first_name' => 'Jane', 'last_name' => 'Jones', ), '00013411' => array( 'id' => 5623, 'first_name' => 'Peter', 'last_name' => 'Doe', ) ); // Example 1: original indexes are lost =( print_r(array_column($records, 'first_name')); // Example 2: new indexes are 'id' column print_r(array_column($records, 'last_name', 'id')); // Example 3: full objects by 'last_name' print_r(array_column($records, null, 'last_name')); // Example 4: objects instead of arrays? $objects = array_map(function($arr) { return (object)$arr; }, $records); print_r(array_column($records, 'last_name', 'id'));
Output for 5.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => John [1] => Sally [2] => Jane [3] => Peter ) Array ( [2135] => Doe [3245] => Smith [5342] => Jones [5623] => Doe ) Array ( [Doe] => Array ( [id] => 5623 [first_name] => Peter [last_name] => Doe ) [Smith] => Array ( [id] => 3245 [first_name] => Sally [last_name] => Smith ) [Jones] => Array ( [id] => 5342 [first_name] => Jane [last_name] => Jones ) ) Array ( [2135] => Doe [3245] => Smith [5342] => Jones [5623] => Doe )
Output for 5.3.0 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/3R2g9 on line 29
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/3R2g9 on line 38
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 T_FUNCTION, expecting ')' in /in/3R2g9 on line 38
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/3R2g9 on line 38
Process exited with code 255.