2013-03-01 120 views
0

我試圖合併2個陣列,而不會丟失值:從兩組值創建數組

$a = array('one', 'two', 'three'); 
$b = array('four', 'five', 'six'); 

我需要的結果是:

array('one', 'two', 'three', 'four', 'five', 'six'); 

我知道可以這樣做使用循環+ []運算符,但它看起來像一個常見的任務,我正在尋找一個更簡單的解決方案,也許使用內置數組函數。有什麼建議麼?

回答

3

語法:array array_merge (array $array1 [, array $... ])

array_merge($一個,$ b)的

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

+0

+1的文檔鏈接 – 2013-03-01 10:41:28

+0

@MarkBaker:感謝您的支持 – 2013-03-01 10:41:51

1

你可以使用array_merge();功能,如:

$result = array_merge($array1, $array2);