<?php // 表示由数据库返回的可能记录集的数组 $a = array( array( 'id' => 5698, 'first_name' => 'Bill', 'last_name' => 'Gates', ), array( 'id' => 4767, 'first_name' => 'Steve', 'last_name' => 'Jobs', ), array( 'id' => 3809, 'first_name' => 'Mark', 'last_name' => 'Zuckerberg', ) ); $last_names = array_column($a, 'last_name'); print_r($last_names); ?>
输出
Array ( [0] => Gates [1] => Jobs [2] => Zuckerberg )
array_column()
array_column() 返回输入数组中某个单一列的值。array_column(array,column_key,index_key);
<?php $a = array("1","2","3"); $b = array_chunk($a,2); echo "<pre>"; print_r($b); ?> <pre>Array ( [0] => Array ( [0] => 1 [1] => 2 ) [1] => Array ( [0] => 3 ) )
array_chunk() 函数把数组分割为新的数组块。
array_chunk(array,size,preserve_key);
$fname=array("Bill","Steve","Mark"); $age=array("60","56","31"); $c=array_combine($fname,$age); print_r($c);
Array
(
[Bill] => 60
[Steve] => 56
[Mark] => 31
)