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') )