先抛出问题,有时候我们接收到的参数是多维数组,我们需要将他们转成普通的数组,比如:
$arr = [
[1, 2, [3, 4]],
[5, 6, [7, 8]],
];
我们需要的结果是元素1变成1,2,3,4,元素2变成5,6,7,8,这时候,我们就可以用foreach配合list来实现,而且非常简单:
foreach ($arr as list($a, $b, list($c, $d))) {
echo $a, ",", $b, ",", $c, ",", $d, PHP_EOL;
...