数组整合 好难哦 求帮忙
程序员文章站
2022-05-14 10:49:12
...
Array( [0] => Array ( [0] => [1] => [2] => [3] => [4] => 134578 ) [1] => Array ( [0] => 1 [1] => 9 [2] => 0 [3] => 7 [4] => 8 ) [3].... [4]....)
整合成
ayyay([0]=>1,[1]=>9,[2]=>0,[3]=>7,[4]=>8134578,)
回复讨论(解决方案)
$array=array(array(1,2,3,4,5),array(6,7,8,9,10));$newArr=array();foreach($array as $k=>$v){ foreach ($v as $k2=>$v) { if(empty($newArr[$k2])) { $newArr[$k2]=$v; } else if($newArr[$k2]3,4 键的值参与整合合吗,请说清楚整合规则。
3 4要整合啊 1楼的盆友貌似不对 - -
$a = array( array('', '', '', '', 134578), array(1, 9, 0, 7, 8),);$r = call_user_func_array('array_map', array_merge(array(null), array_reverse($a)));$r = array_map('join', $r);print_r($r);Array( [0] => 1 [1] => 9 [2] => 0 [3] => 7 [4] => 8134578)
$arr = Array( 0 => Array ( 0 => '', 1 => '', 2 => '', 3 => '', 4 => 134578 ), 1 => Array ( 0 => 1, 1 => 9, 2 => 0, 3 => 7, 4 => 8, ));$t = array();foreach(array_reverse($arr) as $val){ foreach($val as $k=>$v){ if(!isset($t[$k])) $t[$k] = $v; else $t[$k] .= $v; } }print_r($t);