Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

Anonymous
9 years ago
I added a little more functionality to the more popular answers here to support the $index_key parameter for PHP < 5.5

<?php
// for php < 5.5
if (!function_exists('array_column')) {
function
array_column($input, $column_key, $index_key = null) {
$arr = array_map(function($d) use ($column_key, $index_key) {
if (!isset(
$d[$column_key])) {
return
null;
}
if (
$index_key !== null) {
return array(
$d[$index_key] => $d[$column_key]);
}
return
$d[$column_key];
},
$input);

if (
$index_key !== null) {
$tmp = array();
foreach (
$arr as $ar) {
$tmp[key($ar)] = current($ar);
}
$arr = $tmp;
}
return
$arr;
}
}
?>

<< Back to user notes page

To Top