Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Created July 3, 2016 19:23
Show Gist options
  • Save clrockwell/435a7272f7848e4f5399c0c3b9d2ea3a to your computer and use it in GitHub Desktop.
Save clrockwell/435a7272f7848e4f5399c0c3b9d2ea3a to your computer and use it in GitHub Desktop.
<?php
function _array_column($input, $column_key, $index_key = NULL) {
if (function_exists('array_column')) {
return array_column($input, $column_key, $index_key);
}
$result = [];
array_walk($input, function($item) use (&$result, $column_key, $index_key) {
if (!array_key_exists($column_key, $item)) {
return;
}
if (is_null($index_key) || !array_key_exists($index_key, $item)) {
$result[] = $item[$column_key];
} else {
$result[$item[$index_key]] = $item[$column_key];
}
});
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment