array_shift()

array_shift() — Shift an element off the beginning of array.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array keys will be modified to start counting from zero while literal keys won't be affected.

Signature

array_shift(array &$array): mixed

Parameters

ParameterTypeWhat it takes
&$arrayarrayThe input array.

Return value

Returns the shifted value, or null if array is empty or is not an array.

Example

A runnable snippet:

$stack = array("orange", "banana", "apple", "raspberry"); $fruit = array_shift($stack); print_r($stack);

Output:

Array ( [0] => banana [1] => apple [2] => raspberry )

See also

array_unshift(), array_push(), array_pop()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page array_shift() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.