PHP array_unshift function

Last Updated: February 15, 2022

array_unshift — Prepend one or more elements to the beginning of the array

Syntax

 array_unshift(array &$array, mixed ...$values): int

Supports (PHP 4 , PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
array target array
values

Values to prepend

Return Value

Returns the new number of elements in the array.

Example


$input = array("a", "b", "c");

array_unshift($input,"A","B");
print_r($input);

Output

Array ( [0] => A [1] => B [2] => a [3] => b [4] => c ) 
Test