当前位置:Gxlcms > PHP教程 > 怎么把这两个函数相同的键值相加形成新的数组

怎么把这两个函数相同的键值相加形成新的数组

时间:2021-07-01 10:21:17 帮助过:27人阅读


输出:
Array ( [0] => 10,20,30,40 [1] => 1,2,3,4 ) Array ( [0] => 11111 [1] => 22222 )

我想实现的是:
Array ( [0] => 10,20,30,40,11111 [1] => 1,2,3,4,22222)

试过array_merge_recursive() 没效果,请教高手帮帮忙!研究好几天了


回复讨论(解决方案)

$a1 = '10,20,30,40;1,2,3,4';//分号无限往后扩展$a = explode(';', $a1);$b1 = '11111;22222';//分号无限往后扩展,能与$a1对齐叠加$b = explode(';', $b1);$c = array_map(null, $a, $b);print_r($c);
Array(    [0] => Array        (            [0] => 10,20,30,40            [1] => 11111        )    [1] => Array        (            [0] => 1,2,3,4            [1] => 22222        ))

$a1 = '10,20,30,40;1,2,3,4';//分号无限往后扩展$a = explode(';', $a1);$b1 = '11111;22222';//分号无限往后扩展,能与$a1对齐叠加$b = explode(';', $b1); $c=array();foreach($a as $key=>$value){    $c[]=$value.",".$b[$key];}echo '
';print_r($c);

$a1 = '10,20,30,40;1,2,3,4';//分号无限往后扩展$a = explode(';', $a1);$b1 = '11111;22222';//分号无限往后扩展,能与$a1对齐叠加$b = explode(';', $b1);function combine($arr){	return implode(',',$arr);}$c = array_map('combine', array_map(null, $a, $b));print_r($c);



Array
(
[0] => 10,20,30,40,11111
[1] => 1,2,3,4,22222
)

感谢各位高手解答!问题已解决!

人气教程排行