2012-04-05 102 views
3

是否有可能陣列他們這樣的組合,基本上追加到一個大數組:PHP結合數組合併爲一個大陣列

$a = array(1,2,3,4); 
$b = array(5,6,7,8); 
$c = array(1,2,3,4); 

使輸出將是:

$result = array(1,2,3,4,5,6,7,8,1,2,3,4); 

這可能嗎?

感謝您的幫助!

回答

19

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

$a = array(1,2,3,4); 
$b = array(5,6,7,8); 
$c = array(1,2,3,4); 

$out = array_merge($a, $b, $c); 

結果:

Array 
(
    [0] => 1 
    [1] => 2 
    [2] => 3 
    [3] => 4 
    [4] => 5 
    [5] => 6 
    [6] => 7 
    [7] => 8 
    [8] => 1 
    [9] => 2 
    [10] => 3 
    [11] => 4 
) 
+0

謝謝!我之前讀過這樣的例子,但是#2例子讓我困惑,所以我想我會在這裏問... 再次感謝! – 2012-04-05 19:11:53