31st March 2008 - 3 minutes read time
The array_merge() function in PHP is a handy way of adding one or more arrays together. Here is an example of how to use it.
$array1 = array(3, 21, 12); // set up first array
$array2 = array(63, 1, 9); // set up second array
$array3 = array_merge($array1, $array2); // merge arrays
print_r($array3); // print!
This will print the following.
Array
(
[0] => 3
[1] => 21
[2] => 12
[3] => 63
[4] => 1
[5] => 9
)
The only problem with this function is that it resets any numeric keys, so the following example would produce the wrong result.