Append

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

Syntax

array append(array $input, any $items)

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

Parameters

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

Example

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

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.

Notes

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.