一般array_column 是获取二维数组的制定列,组成新的数组输出。
注意:可以制定第三个参数,指定输出数组的key
<?php $arr = [ ['id' => 11, 'name' => 'aa'], ['id' => 22, 'name' => 'bb',], ['id' => 44, 'name' => 'cc'], ['id' => 33, 'name' => 'dd'] ]; // 示例1: print_r(array_column($arr, 'name')); // 运行结果: Array ( [0] => aa [1] => bb [2] => cc [3] => dd ) // 示例2: print_r(array_column($arr,'name','id')); // 运行结果: ( [11] => aa [22] => bb [44] => cc [33] => dd ) // 示例3: print_r(array_column($arr, null, 'name')); // 运行结果: Array ( [aa] => Array ( [id] => 11 [name] => aa ) [bb] => Array ( [id] => 22 [name] => bb ) [cc] => Array ( [id] => 44 [name] => cc ) [dd] => Array ( [id] => 33 [name] => dd ) )