Hướng dẫn array_column multidimensional php
(PHP 5 >= 5.5.0, PHP 7, PHP 8) array_column — Return the values from a single column in the input array Descriptionarray_column(array Parametersarray 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 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, prior to PHP 8.0.0, objects supporting conversion to string were also allowed). Return ValuesReturns an array of values representing a single column from the input array. Changelog
ExamplesExample #1 Get the column of first names from a recordset
The above example will output: Array ( [0] => John [1] => Sally [2] => Jane [3] => Peter ) Example #2 Get the column of last names from a recordset, indexed by the "id" column
The above example will output: Array ( [2135] => Doe [3245] => Smith [5342] => Jones [5623] => Doe ) Example #3 Get the column of usernames from the public "username" property of an object
__construct(string $username) The above example will output: Array ( [0] => user 1 [1] => user 2 [2] => user 3 ) Example #4 Get the column of names from the private "name" property of an object using the magic __get() method.
__construct(string $name) The above example will output: Array ( [0] => Fred [1] => Jane [2] => John ) If __isset() is not provided, then an empty array will be returned. mohanrajnr at gmail dot com ¶ 7 years ago
WARrior ¶ 8 years ago
balbuf ¶ 4 years ago
ff2 AT hotmail DOT co DOT uk ¶ 4 years ago
$indexkey === null) { $result[] = $val; } yangmeishu at live dot com ¶ 2 years ago
= [ till at etill dot net ¶ 7 years ago
nino at recgr dot com ¶ 6 years ago
miguelfzarth at gmail dot com ¶ 6 years ago
antonfedonjuk at gmail dot com ¶ 7 years ago
Anonymous ¶ 6 years ago
$index_key !== null) { Carlos Granados ¶ 6 years ago
array_intersect_key($data, $keep); Hiranmoy Chatterjee ¶ 6 months ago
benjam ¶ 6 years ago
= array( oleg dot bolden at gmail dot com ¶ 4 months ago
$output; Sbastien ¶ 5 months ago
1184427175 at qq dot com ¶ 5 years ago
Nolan chou ¶ 6 years ago
kaspar dot wilbuer at web dot de ¶ 6 years ago
katrinaelaine6 at gmail dot com ¶ 5 years ago
= [ kiler129 @ nowhere ¶ 7 years ago
hypxm at qq dot com ¶ 7 years ago
marianbucur17 at yahoo dot com ¶ 7 years ago
robbieaverill[at]gmail.com ¶ 7 years ago
myles at smyl dot es ¶ 7 years ago
greensea ¶ 6 years ago
$index_key === NULL || !isset($v[$index_key])) { coviex ¶ 7 years ago
robsonvnasc at gmail dot com ¶ 5 years ago
Dominik59 ¶ 5 years ago
|