Created
July 3, 2016 19:23
-
-
Save clrockwell/435a7272f7848e4f5399c0c3b9d2ea3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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