首页  >  文章  >  后端开发  >  php数组合并

php数组合并

WBOY
WBOY原创
2016-10-11 14:23:341212浏览

有三个一维数组,
Array ( [0] => 12312 [1] => 2321 [2] => 12321 )
Array ( [0] => 133 [1] => 444 [2] => 888 )
Array ( [0] => qqqqqqq [1] => wqwq [2] => wqe )

合并成
array( [orderno] => 12312 [deliverysn] => 133 [deliverycorpname] => qqqqqqq)

<code>array( [orderno] => 2321 [deliverysn] => 444 [deliverycorpname] => wqwq )  一次类推怎么做</code>

回复内容:

有三个一维数组,
Array ( [0] => 12312 [1] => 2321 [2] => 12321 )
Array ( [0] => 133 [1] => 444 [2] => 888 )
Array ( [0] => qqqqqqq [1] => wqwq [2] => wqe )

合并成
array( [orderno] => 12312 [deliverysn] => 133 [deliverycorpname] => qqqqqqq)

<code>array( [orderno] => 2321 [deliverysn] => 444 [deliverycorpname] => wqwq )  一次类推怎么做</code>

不知道题主是不是这个意思,效果如下
https://3v4l.org/8r0ko

<code class="php">//首先要确定这3个数组是关联数组和所包含的元素个数都是一样的
$arr_orderno = [12321,321,321];
$arr_deliverysn = [7,8,9];
$arr_deliverycorpname = ['asd','qwe','zxc'];

$arr_merge= [];
for($i = 0; $i </code>

<code>foreach($arr_a as $k=>$v){
    $arr_{$k}['orderno'] = $v;
    $arr_{$k}['deliverysn'] = $arr_b[$k];
    $arr_{$k}['deliverycorpname'] = $arr_c[$k];
}</code>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn