m
PHP快速将一个多维数转换成一维数组
使用标准PHP库(SPL)递归:
$a = array(1,2,array(3,4, array(5,6,7), 8), 9);
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($a));
foreach($it as $v) {
echo $v, " ";
}
//print
1 2 3 4 5 6 7 8 9
取得数组某个键值:
$array = [['value' => 1], ['value' => 2], ['value' => 3]];
implode(', ', array_map(function($value) {
return $value['value'];
}, $array));
//print
1, 2, 3