array_unshift

array

Adds an element to the start of an array

Syntax

array_unshift(array, value)

Parameters

array (array)

The array to add an element to

value (any)

The value to add at the beginning

Returns

array

A new array with the value added at the start

Examples

Input:
[2, 3] | array_unshift(1)
Output:
[1, 2, 3]
Input:
["b", "c"] | array_unshift("a")
Output:
["a", "b", "c"]

The array_unshift() function adds an element to the beginning of an array, returning a new array with the value prepended.

Usage

This function is useful for adding headers, prepending new items to a list, or building arrays from the front.