1.二维数组转一维数组
示例
$records = array(
array( 'id' => 2135, 'first_name' => 'John','last_name' => 'Doe', ),
array('id' => 3245,'first_name' => 'Sally','last_name' => 'Smith', ),
array('id' => 5342,'first_name' => 'Jane','last_name' => 'Jones',),
array('id' => 5623,'first_name' => 'Peter','last_name' => 'Doe',)
);
(1).可以用foreach循环处理数组
foreach($msg as $k => $v){
$ids[] = $id;
$names[] = $name;
}
(2).用php函数处理
$last_names = array_column($records, 'last_name');
Array([45]=>jack,[34]=>mary,[78]=>lili)
$last_names = array_column($records, 'last_name', 'id');
Array( [2135] => Doe, [3245] => Smith, [5342] => Jones, [5623] => Doe)
网友评论