161 of 410 menu

The array_shift Function

The array_shift function extracts and returns the first element of an array. This element is then removed from the array.

Syntax

array_shift(array &$array): mixed

Example

Let's extract and output the first element of the array:

<?php $arr = [1, 2, 3, 4, 5]; echo array_shift($arr); ?>

Code execution result:

1

The array $arr will look like this:

[2, 3, 4, 5]

See Also

  • the array_pop function,
    which extracts the last element of an array
byenru