通过 php 自身的迭代器 RecursiveIteratorIterator 实现
$arr = [
[
"b",
1,
2,
3,
],
[
4,
5,
"a",
6,
],
[
1,
[
7,8,9
],
],
];
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arr));
$str = "";
foreach ($iterator as $key => $val) {
$str .= $val.",";
}
var_dump(trim($str,","));
// 输出结果
// string(23) "b,1,2,3,4,5,a,6,1,7,8,9"
网友评论