Created
April 30, 2014 10:25
-
-
Save nicklasos/965ebf6ceddda1ad4310 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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