getColumn() public static method
Returns the values of a specified column in an array.
The input array should be multidimensional or an array of objects.
For example,
$array = [ ['id' => '123', 'data' => 'abc'], ['id' => '345', 'data' => 'def'], ]; $result = ArrayHelper::getColumn($array, 'id'); // the result is: ['123', '345'] // using anonymous function $result = ArrayHelper::getColumn($array, function ($element) { return $element['id']; });
public static array getColumn ( $array, $name, $keepKeys = true ) | ||
---|---|---|
$array | array | |
$name | string|Closure | |
$keepKeys | boolean |
Whether to maintain the array keys. If false, the resulting array will be re-indexed with integers. |
return | array |
The list of column values |
Please login to continue.