PHP 8 reference · Array Functions
PHP array_pop() Function
Remove the last element of an array and return it. Returns null if the array is empty.
PHP 8 Since 4.0
Syntax
array_pop(array &$array): mixed
Parameters
| Parameter | Description |
|---|---|
array |
The array (changed in place). |
Return value
The removed value, or null.
Examples
<?php
$stack = ["html", "css", "php"];
echo array_pop($stack), "\n";
print_r($stack);
Output
php
Array
(
[0] => html
[1] => css
)<?php
$empty = [];
var_dump(array_pop($empty));
Output
NULL
Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
In other languages
list.pop()· Pythonarray.pop()· JavaScript
Related
array_push()· Add one or more elements to the end of an array and return its new length. $array[] = $value does the same for one value.array_shift()· Remove the first element of an array and return it. Numeric keys are renumbered from 0; string keys stay.array_key_last()· Return the last key of an array without moving its internal pointer, or null for an empty array. Added in 7.3.- PHP Arrays · tutorial
- PHP Array Functions · tutorial