Skip to content

Instantly share code, notes, and snippets.

@nicklasos
Created April 30, 2014 10:25
Show Gist options
  • Save nicklasos/965ebf6ceddda1ad4310 to your computer and use it in GitHub Desktop.
Save nicklasos/965ebf6ceddda1ad4310 to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('array_column')) {
function array_column(array $input, $columnKey, $indexKey = null) {
$result = array();
if (null === $indexKey) {
if (null === $columnKey) {
// trigger_error('What are you doing? Use array_values() instead!', E_USER_NOTICE);
$result = array_values($input);
}
else {
foreach ($input as $row) {
$result[] = $row[$columnKey];
}
}
}
else {
if (null === $columnKey) {
foreach ($input as $row) {
$result[$row[$indexKey]] = $row;
}
}
else {
foreach ($input as $row) {
$result[$row[$indexKey]] = $row[$columnKey];
}
}
}
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment