2017-07-10 155 views
1

我有一個PHP數組像下面的一個,我想多陣列相結合,一個數組:結合的多陣列一個陣列

Array 
(
    [0] => ADB_DW2017 
    [1] => LM9 
    [2] => MS_OF2013 
) 
Array 
(
    [0] => NK 
    [1] => PV 
    [2] => NK 
) 
Array 
(
    [0] => 15 
    [1] => 25 
    [2] => 10 
) 
Array 
(
    [0] => 250 
    [1] => 111 
    [2] => 150 
) 
Array 
(
    [0] => 450 
    [1] => 123 
    [2] => 250 
) 
Array 
(
    [0] => 0 
    [1] => Mien thue 
    [2] => 5 
) 
Array 
(
    [0] => 200 
    [1] => 12 
    [2] => 100 
) 
Array 
(
    [0] => 6.750 
    [1] => 3.075 
    [2] => 2.500 
) 

我想這樣的結合,具有最高的性能:

Array 
(
[ADB_DW2017]=>array([suppiler]=>NK 
        [min_pro]=>15 
        [max_pro]=>250 
        [avg_pro]=>450 
        [tax]=>0 
        [com]=>200 
        [sum]=>6.750 
       ) 
) 

我的問題是:如何多陣列在PHP中具有最高的性能結合起來,一個數組?

+0

是否有可能給進程產生這些陣列?所以我們可以在生成時設置你的願望輸出 –

+0

[PHP將數組合併成一個大數組]可能重複(https://stackoverflow.com/questions/10034521/php-combine-arrays-into-one-big-陣列) –

回答

1

我假設數組名稱爲$first_array,$second_array,......(因此請相應地更改數字名稱)。

做象下面這樣: -

$final_array = array(); 
foreach ($first_array as $key=> $arr){ 
    $final_array[$arr] =array(
     'suppiler'=>(isset($second_array[$key]))? $second_array[$key]: '', 
     'min_pro'=>(isset($third_array[$key]))? $third_array[$key]: 0, 
     'max_pro'=>(isset($fourth_array[$key]))? $fourth_array[$key]: 0, 
     'avg_pro'=>(isset($fifth_array[$key]))? $fifth_array[$key]: 0, 
     'tax'=>(isset($sixth_array[$key]))? $sixth_array[$key]: '', 
     'com'=>(isset($seventh_array[$key]))? $seventh_array[$key]: 0, 
     'sum'=>(isset($eigth_array[$key]))? $eigth_array[$key]: 0 
    ); 
} 
echo "<pre/>";print_r($final_array); 

輸出: - https://eval.in/829938