Home > Backend Development > PHP Tutorial > 数组整合 好难哦 求帮忙

数组整合 好难哦 求帮忙

WBOY
Release: 2016-06-23 13:03:08
Original
876 people have browsed it

Array(    [0] => Array        (            [0] =>             [1] =>             [2] =>             [3] =>             [4] => 134578        )    [1] => Array        (            [0] => 1            [1] => 9            [2] => 0            [3] => 7            [4] => 8        )    [3]....    [4]....)
Copy after login


整合成
ayyay([0]=>1,[1]=>9,[2]=>0,[3]=>7,[4]=>8134578,)
Copy after login


回复讨论(解决方案)

$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]<=$v)        {            $newArr[$k2]=$v;        }    }}print_r($newArr);
Copy after login

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);
Copy after login
Array(    [0] => 1    [1] => 9    [2] => 0    [3] => 7    [4] => 8134578)
Copy after login

$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);
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template