Last active
July 5, 2025 17:47
-
-
Save stemar/84a0925a4262fd17ba4465e07d1d0a7b to your computer and use it in GitHub Desktop.
array_column() pre-PHPv5.5
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 | |
| if (!function_exists('array_column')) { | |
| function array_column(array $array, $column_key, $index_key = NULL) { | |
| $output = array(); | |
| foreach ($array as $row) { | |
| if (is_null($index_key)) { | |
| $output []= is_null($column_key) ? $row : $row[$column_key]; | |
| } | |
| else { | |
| $output[$row[$index_key]] = is_null($column_key) ? $row : $row[$column_key]; | |
| } | |
| } | |
| return $output; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment