2011-11-23 211 views
0

如何將以下格式的少數數組合併成一個數組。合併PHP數組

謝謝。

Array 
(
    [apple] => 1 
    [mango] => 5 
    [banana] => 3 
) 
Array 
(
    [car] => 2 
    [bus] => 7 
    [moto] => 8 
) 
Array 
(
    [rain] => 14 
    [snow] => 7 
    [sun] => 12 
) 

新陣列

Array 
(
    [0] => Array 
     (
      [apple] => 1 
      [mango] => 5 
      [banana] => 3 
     ) 

    [1] => Array 
     (
      [car] => 2 
      [bus] => 7 
      [moto] => 8 
     ) 

    [2] => Array 
     (
      [rain] => 14 
      [snow] => 7 
      [sun] => 12 
     )   

) 
+0

array_merge:http://php.net/manual/en/ function.array-merge.php – malletjo

+0

@racar不適用於想要的結果 – Phil

+0

我同意,array_merge(array($ array1),array($ array2)...)不是一個很好的方法來做到這一點 – malletjo

回答

7

這真的很簡單

$newArray = array($array1, $array2, $array3); 

以上字面上

$newArray = array(
    array('apple' => 1, 'mango' => 5, 'banana' => 3), 
    array('car' => 2, 'bus' => 7, 'moto' => 8), 
    array('rain' => 14, 'snow' => 7, 'sun' => 12) 
);