Array_column () returns the column with the specified key name in the array (PHP55.5.0) array_column-returns a column specified in the array. What if php version is earlier than 5.5.0? We can customize the following code from onethinkOneThinkThinkPHP array_column () to return the column (PHP 5 = 5.5.0) with the specified key name in the array array_column-to return the specified column in the array
What if php version is earlier than 5.5.0? We can customize the following code from onethink OneThink ThinkPHP.
Array_column () returns the column with the specified key name in the array.
(PHP 5> = 5.5.0)
Array_column-returns a specified column in the array.
What if php version is earlier than 5.5.0? We customize
The following code is taken from onethink OneThink ThinkPHP.
/*** Return a specified column in the array * http://www.onethink.cn */Application/Common/function. php ** array_column-PHP 5> = 5.5.0 default function * PHP 5 <5.5.0, use the custom function ** @ access public * @ param array $ input to retrieve the multi-dimensional array of the array Column (or result set) * @ param string $ columnKey the column to be returned. It can be the index of the index array or the key of the column associated with the array. It can also be NULL. In this case, the entire array is returned (it works very well when the indexKey parameter is used to reset the array key) * @ param string $ indexKey is used as the column for returning the index/Key of the array, it can be an integer index of the column or a string key value. * @ Return array */if (! Function_exists ('array _ column ') {function array_column (array $ input, $ columnKey, $ indexKey = null) {$ result = array (); if (null ===$ indexKey) {if (null ===$ columnKey) {$ result = array_values ($ input);} else {foreach ($ input as $ row) {$ result [] = $ row [$ columnKey] ;}} else {if (null ===$ columnKey) {foreach ($ input as $ row) {$ result [$ row [$ indexKey] = $ row ;}} else {foreach ($ input as $ row) {$ result [$ row [$ indexKey] = $ row [$ columnKey] ;}} return $ result ;}}
2135, 'First _ name' => 'john', 'last _ name' => 'doe ',), array ('id' => 3245, 'First _ name' => 'Sally ', 'last _ name' => 'Smith',), array ('id' => 5342, 'First _ name' => 'Jane ', 'last _ name' => 'Jones',), array ('id' => 5623, 'First _ name' => 'Peter ', 'last _ name' => 'doe',); $ first_names = array_column ($ records, 'First _ name '); print_r ($ first_names);?> Array ([0] => John [1] => Sally [2] => Jane [3] => Peter)