Append can be used to add items to the end of an array. This can be useful for merging static and dynamic data.


array append(array $input, any $items)

Appends $items to the end of the $input array.


$input: The array to append items to.
$items: The items to append to the input array.


    "Array": ["a", "b", "c"]
    NewArray: append(Array, 'd', 'e')
    "NewArray": [

In this example, the separate string values of “d” and “e” are added to the “Array” of strings.

Any value (string, object, array, integer, etc.) can be appended.


Manual append/prepend

In the above example, the result could have been achieved without using the Append() function, by simply creating an additional array and flattening it afterward. Like this:

    NewArray: [Arr, 'd', 'e'][]

The same trick can be used to prepend items in an array. This is useful since there is no built-in function to prepend like there is for appending.