Menu Samaritan's Purse

ARRAY_COLUMN

Return the values from a single column in the input array

SYNTAX

array_column ( array $input , mixed $column_key [, mixed $index_key = NULL ] ) : array

PARAMETERS

input

A multi-dimensional array or an array of objects from which to pull a column of values from. If an array of objects is provided, then public properties can be directly pulled. In order for protected or private properties to be pulled, the class must implement both the __get() and __isset() magic methods.

column_key

The column of values to return. This value may be an integer key of the column you wish to retrieve, or it may be a string key name for an associative array or property name. It may also be NULL to return complete arrays or objects (this is useful together with index_key to reindex the array).

index_key

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. The value is cast as usual for array keys (however, objects supporting conversion to string are also allowed).

RETURN

Returns an array of values representing a single column from the input array.

EXAMPLES

INPUT COLUMN_KEY

Array
(
    [0] => John
    [1] => Sally
    [2] => Jane
    [3] => Peter
)

INDEX_KEY

Array
(
    [2135] => John
    [3245] => Sally
    [5342] => Jane
    [5623] => Peter
)

PUBLIC

Array
(
    [0] => John
    [1] => Sally
    [2] => Jane
    [3] => Peter
)

PRIVATE

Array
(
    [0] => John
    [1] => Sally
    [2] => Jane
    [3] => Peter
)

PHP