3v4l.org

run code in 300+ PHP versions simultaneously
<?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: no pick and no index print_r(array_column($records, null)); // Example 5: objects instead of arrays? $objects = array_map(function($arr) { return (object)$arr; }, $records); print_r($objects); print_r(array_column($records, 'last_name', 'id'));
Output for 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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 ( [0] => Array ( [id] => 2135 [first_name] => John [last_name] => Doe ) [1] => Array ( [id] => 3245 [first_name] => Sally [last_name] => Smith ) [2] => Array ( [id] => 5342 [first_name] => Jane [last_name] => Jones ) [3] => Array ( [id] => 5623 [first_name] => Peter [last_name] => Doe ) ) Array ( [4] => stdClass Object ( [id] => 2135 [first_name] => John [last_name] => Doe ) [8] => stdClass Object ( [id] => 3245 [first_name] => Sally [last_name] => Smith ) [2] => stdClass Object ( [id] => 5342 [first_name] => Jane [last_name] => Jones ) [00013411] => stdClass Object ( [id] => 5623 [first_name] => Peter [last_name] => Doe ) ) Array ( [2135] => Doe [3245] => Smith [5342] => Jones [5623] => Doe )
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/GQPK7 on line 29
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/GQPK7 on line 41
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/GQPK7 on line 41
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/GQPK7 on line 41
Process exited with code 255.

preferences:
193.24 ms | 401 KiB | 313 Q