Php returns the specified column in the array (php5.5.0 default function array_column () in php & lt; 5.5.0 application)
/*** 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 ;}}
2. [Code]Demo
Jump
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);?>
3. [Code]The demo will output:
Jump
Array( [0] => John [1] => Sally [2] => Jane [3] => Peter)