array_pop()

array_pop() — Pop the element off the end 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_pop() pops and returns the value of the last element of array, shortening the array by one element.

Signature

array_pop(array &$array): mixed

Parameters

ParameterTypeWhat it takes
&$arrayarrayThe array to get the value from.

Return value

Returns the value of the last element of array. If array is empty, null will be returned.

Example

A runnable snippet:

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

Output:

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

See also

array_push(), array_shift(), array_unshift()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page array_pop() (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.