Voting

: min(seven, five)?
(Example: nine)

The Note You're Voting On

antonfedonjuk at gmail dot com
9 years ago
My version is closer to the original than http://github.com/ramsey/array_column
<?php
/**
* Provides functionality for array_column() to projects using PHP earlier than
* version 5.5.
* @copyright (c) 2015 WinterSilence (http://github.com/WinterSilence)
* @license MIT
*/
if (!function_exists('array_column')) {
/**
* Returns an array of values representing a single column from the input
* array.
* @param array $array A multi-dimensional array from which to pull a
* column of values.
* @param mixed $columnKey The column of values to return. This value may
* be the integer key of the column you wish to retrieve, or it may be
* the string key name for an associative array. It may also be NULL to
* return complete arrays (useful together with index_key to reindex
* the array).
* @param mixed $indexKey The column to use as the index/keys for the
* returned array. This value may be the integer key of the column, or
* it may be the string key name.
* @return array
*/
function array_column(array $array, $columnKey, $indexKey = null)
{
$result = array();
foreach (
$array as $subArray) {
if (!
is_array($subArray)) {
continue;
} elseif (
is_null($indexKey) && array_key_exists($columnKey, $subArray)) {
$result[] = $subArray[$columnKey];
} elseif (
array_key_exists($indexKey, $subArray)) {
if (
is_null($columnKey)) {
$result[$subArray[$indexKey]] = $subArray;
} elseif (
array_key_exists($columnKey, $subArray)) {
$result[$subArray[$indexKey]] = $subArray[$columnKey];
}
}
}
return
$result;
}
}
?>

<< Back to user notes page

To Top