How can one append an array to another array in PHP?

To append an array to another array in PHP, you can use the array_merge() function. This function takes two or more arrays as arguments and merges them into a single array. The elements of the second array are added to the end of the first array. This is useful when you want to combine two arrays without overwriting any existing keys.

// Define two arrays
$array1 = [1, 2, 3];
$array2 = [4, 5, 6];

// Append array2 to array1
$mergedArray = array_merge($array1, $array2);

// Output the merged array
print_r($mergedArray);