代码示例
$arr= [ [ '1', '2' ], [ '1', '4', '5' ], ]; functionflatten($arr) { $result= []; foreach ($arras$k=>$v) { if (is_array($v)) { $result=array_merge($result, flatten($v)); } else { $result[] =$v; } } return$result; } print_r(json_encode(flatten($arr))); // ["1","2","1","4","5"]// 去重处理,注意需要取值操作print_r(json_encode(array_values(array_unique(flatten($arr))))); // ["1","2","4","5"]
> 参考
> [php 如何扁平化下面的数组?](https://www.oschina.net/question/116373_2196782)