AI智能
改变未来

php 二维数组合并为一维数组


php 二维数组合并为一维数组

案例demo

<?php$data = [];$item = [];$item[] = \"百度\";$item[] = \"阿里\";$data[] = $item;$item = [];$item[] = \"百媚\";$item[] = \"千骄\";$data[] = $item;$extra = array_reduce($data, \'array_merge\', []);var_dump($data);var_dump($extra);

返回结果

array (size=2)0 =>array (size=2)0 => string \'百度\' (length=6)1 => string \'阿里\' (length=6)1 =>array (size=2)0 => string \'百媚\' (length=6)1 => string \'千骄\' (length=6)array (size=4)0 => string \'百度\' (length=6)1 => string \'阿里\' (length=6)2 => string \'百媚\' (length=6)3 => string \'千骄\' (length=6)
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » php 二维数组合并为一维数组