array_pop

mixed array_pop(array array) 

Returns and deletes the last element of an array.

Returns:

Last element of the given array; NULL on failure or if the array is empty

Description:

array_pop() returns the last value of array and deletes that element from the array. This also works for multidimensional arrays, so if the last element happens to be an array, that array is returned and deleted from array .

This function can be used with array_push() to treat arrays as stacks.

Warning:

This function directly alters the array passed to it.

Version:

PHP 4

See also:

array_push() 
array_shift() 
array_unshift() 

Example:

Pop elements from various arrays
 $a1 = array('one', 'two', 'three', 'four'); $a2 = array('jan' => '01', 'feb' => '02', 'mar' ...

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.