首頁  >  文章  >  後端開發  >  php數組合併

php數組合併

WBOY
WBOY原創
2016-10-11 14:23:341211瀏覽

有三個一維數組,
Array ( [0] => 12312 [1] => 2321 [2] => 12321 )
Array ( [0] => 133 [1] => 4444 [2] => 888 )
Array ( [0] => qqqqqqq [1] => wqwq [2] => wqe )

合併成
array( [orderno] => 12312 [deliverysn] => 133 [deliverycorpname] => qqqqqqqq)

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

回覆內容:

有三個一維數組,
Array ( [0] => 12312 [1] => 2321 [2] => 12321 )
Array ( [0] => 133 [1] => 4444 [2] => 888 )
Array ( [0] => qqqqqqq [1] => wqwq [2] => wqe )

合併成
array( [orderno] => 12312 [deliverysn] => 133 [deliverycorpname] => qqqqqqqq)

<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 < count($arr_orderno); $i++){
  $arr_merge[$i] = [$arr_orderno[$i], $arr_deliverysn[$i], $arr_deliverycorpname[$i]];
}

$arr_key = ['orderno', 'deliverysn', 'deliverycorpname'];

$arr = [];
foreach ($arr_merge as $value) {
  $arr[] = array_combine($arr_key, $value);
}


print_r($arr);</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