Skip to content

Instantly share code, notes, and snippets.

@stemar
Last active July 5, 2025 17:47
Show Gist options
  • Save stemar/84a0925a4262fd17ba4465e07d1d0a7b to your computer and use it in GitHub Desktop.
Save stemar/84a0925a4262fd17ba4465e07d1d0a7b to your computer and use it in GitHub Desktop.
array_column() pre-PHPv5.5
<?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