| 1 |
<?php |
| 2 |
if (! function_exists('array_column')) { |
| 3 |
function array_column_bc(array $input, $columnKey, $indexKey = null) { |
| 4 |
$array = array(); |
| 5 |
foreach ($input as $value) { |
| 6 |
if ( !array_key_exists($columnKey, $value)) { |
| 7 |
// trigger_error("Key \"$columnKey\" does not exist in array"); |
| 8 |
return false; |
| 9 |
} |
| 10 |
if (is_null($indexKey)) { |
| 11 |
$array[] = $value[$columnKey]; |
| 12 |
} |
| 13 |
else { |
| 14 |
if ( !array_key_exists($indexKey, $value)) { |
| 15 |
// trigger_error("Key \"$indexKey\" does not exist in array"); |
| 16 |
return false; |
| 17 |
} |
| 18 |
if ( ! is_scalar($value[$indexKey])) { |
| 19 |
// trigger_error("Key \"$indexKey\" does not contain scalar value"); |
| 20 |
return false; |
| 21 |
} |
| 22 |
$array[$value[$indexKey]] = $value[$columnKey]; |
| 23 |
} |
| 24 |
} |
| 25 |
return $array; |
| 26 |
} |
| 27 |
} |