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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array_pop(array &$array): mixed

Parameters

ParameterDescription
array The array (changed in place).

Return value

The removed value, or null.

Examples

Take the last elementTry it yourself
<?php
$stack = ["html", "css", "php"];
echo array_pop($stack), "\n";
print_r($stack);

Output

php
Array
(
    [0] => html
    [1] => css
)
Empty arraysTry it yourself
<?php
$empty = [];
var_dump(array_pop($empty));

Output

NULL

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?