PHP二维数组用某个字段的值当做键名
作者:互联网
$array = array( array('id'=>'3','name'=>'tom'), array('id'=>'5','name'=>'jerry'), array('id'=>'24','name'=>'spike') ); $newArray1 = array_column($array,NULL,'id'); var_dump($newArray1); //结果 array( '3'=>array('id'=>'3','name'=>'tom'), '5'=>array('id'=>'5','name'=>'jerry'), '24'=>array('id'=>'24','name'=>'spike') ) $newArray2 = array_column($array,NULL,'name'); var_dump($newArray2); //结果 array( 'tom'=>array('id'=>'3','name'=>'tom'), 'jerry'=>array('id'=>'5','name'=>'jerry'), 'spike'=>array('id'=>'24','name'=>'spike') )
标签:24,键名,jerry,字段,spike,array,PHP,id,name 来源: https://blog.51cto.com/u_13481146/2819276