array_column()
返回二維數(shù)組列的鍵值枷邪,
返回修改第一層鍵名的整個二維數(shù)組;
不會修改原數(shù)組抖部;
基礎(chǔ)語法:
array array_column(array $array , mixed $column_key [,mixed $index_key = NULL]);
array -返回數(shù)組说贝;
array $array -被操作原始數(shù)組;
column_key -需要返回的列慎颗;
index_key -返回的列數(shù)組的鍵名乡恕,or 返回整個二維數(shù)組的第一層次的鍵名;
語法結(jié)構(gòu)1:
array array_column(array $array ,mixed $column_key);
返回有列值構(gòu)成的索引數(shù)組俯萎;
實例:
<?php
$a_persnal_info = [
'bill' =>['name'=>'bill','age'=>20],
'tom'=>['name'=>'tom','age'=>33]
];
$a_age = array_column($a_personal_info,'age');
print_r($a_age);
#output : Array ( [0] => 55 [1] => 30 [2] => 20 );
?>
語法結(jié)構(gòu)2:
array array_column(array $array ,mixed $column_key ,mixed $index_key);
返回列值構(gòu)成的關(guān)聯(lián)數(shù)組傲宜,鍵名是 index_key 的值;
實例:
$a_personal_info = [
'bill' =>['name'=>'bill','age'=>20],
'tom'=>['name'=>'tom','age'=>33]
];
$a_personal_age = array_columne($a_personal_info,'age','name');
print_r($a_personal_age);
#output : Array ( [bill] => 20 [tom] => 33 );
語法結(jié)構(gòu)3:
array array_columne(array $array ,NULL,mixed $index_key);
返回替換第一層鍵名的二維數(shù)組夫啊;
實例:
$a_personal_info = [
0 =>['name'=>'bill','age'=>20],
1=>['name'=>'tom','age'=>33]
];
print_r(array_columne($a_personal_info,NULL,'name'));
#output :
Array (
[bill] => Array ( [name] => bill [age] => 20 )
[tom] => Array ( [name] => tom [age] => 33 )
)
總結(jié):
array_column()
返回列值數(shù)組函卒;
返回修改鍵名后的二維數(shù)組;