3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $foo = ARRAY(); $foo[0] = ARRAY('key'=>'key0', 'value'=>'value0', 'text'=>'text0', 'int'=>1000); $foo[1] = ARRAY('key'=>'key1', 'value'=>'value1', 'text'=>'text1', 'int'=>1001); $foo[2] = ARRAY('key'=>'key2', 'value'=>'value2', 'text'=>'text2', 'int'=>1002); $foo[3] = ARRAY('key'=>'key3', 'value'=>'value3', 'text'=>'text3', 'int'=>1003); $foo[5] = ARRAY('key'=>'key5', 'value'=>'value5', 'text'=>'text5', 'int'=>1005); $foo[7] = ARRAY('key'=>'key7', 'value'=>'value7', 'text'=>'text7', 'int'=>1007); // reset indexes, set column 'value' as values $result1 = ArrayColumn($foo, 'value'); var_export($result1); print "\n\n"; // re-index with column 'key', use column 'value' as values $result2 = ArrayColumn($foo, 'value', 'key'); var_export($result2); print "\n\n"; // re-index with column 'int', use column 'value' as values $result3 = ArrayColumn($foo, 'value', 'int'); var_export($result3); print "\n\n"; // re-index with column 'int', use COMPLETE ARRAY as values $result4 = ArrayColumn($foo, NULL, 'int'); var_export($result4); print "\n\n"; function ArrayColumn($arr=FALSE, $column_value=NULL, $column_index=NULL, $unique=FALSE) { $arr = array_column($arr, $column_value, $column_index); if ($unique === TRUE) { $arr = array_unique($arr); } return $arr; } ?>
Output for 5.5.24 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array ( 0 => 'value0', 1 => 'value1', 2 => 'value2', 3 => 'value3', 4 => 'value5', 5 => 'value7', ) array ( 'key0' => 'value0', 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key5' => 'value5', 'key7' => 'value7', ) array ( 1000 => 'value0', 1001 => 'value1', 1002 => 'value2', 1003 => 'value3', 1005 => 'value5', 1007 => 'value7', ) array ( 1000 => array ( 'key' => 'key0', 'value' => 'value0', 'text' => 'text0', 'int' => 1000, ), 1001 => array ( 'key' => 'key1', 'value' => 'value1', 'text' => 'text1', 'int' => 1001, ), 1002 => array ( 'key' => 'key2', 'value' => 'value2', 'text' => 'text2', 'int' => 1002, ), 1003 => array ( 'key' => 'key3', 'value' => 'value3', 'text' => 'text3', 'int' => 1003, ), 1005 => array ( 'key' => 'key5', 'value' => 'value5', 'text' => 'text5', 'int' => 1005, ), 1007 => array ( 'key' => 'key7', 'value' => 'value7', 'text' => 'text7', 'int' => 1007, ), )
Output for 5.0.0 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/fnoHk on line 30
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: array_column() in /in/fnoHk on line 30
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: array_column() in /in/fnoHk on line 30
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: array_column() in /in/fnoHk on line 30