Example 1 — Join Two Lists
Combine two simple arrays into one.
<?php
$first = [1, 2];
$second = [3, 4];
$all = array_merge($first, $second);
echo implode(", ", $all), PHP_EOL; How It Works
- Create two arrays. One holds 1 and 2, the other 3 and 4.
- Call array_merge(). The second array is added after the first.
- Print the result. All four numbers are in order.
- The originals are unchanged. A new array is returned.

