array_shift

mixed array_shift(array array) 

Returns the first element of the array and removes the element from the array.

Returns:

First element of an array; NULL on failure or if the array is empty

Description:

This function pulls the first element off the array and returns it, while shortening the array by the first element and moving all other elements down by one.

Used with array_push(), this function can make an array act in FIFO (first-in-first-out) fashion.

Warning:

This function directly alters the array passed to it.

Version:

PHP 4

See also:

array_pop() 
array_push() 
array_unshift() 

Example:

Pop an element from the beginning of an array
 $arr1 = array("one", "two", "three", "four"); echo "First element was: ", array_shift($arr1), ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.