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
phparray_shift(array &$array): mixed
Example
Let's extract and output the first element of the array:
php<?php
$arr = [1, 2, 3, 4, 5];
echo array_shift($arr);
?>
Code execution result:
php1
The array $arr will look like this:
php[2, 3, 4, 5]
See Also
-
the
array_popfunction,
which extracts the last element of an array