The array_pop Function
The array_pop function extracts and returns
the last element of an array. This element is
then removed from the array.
Syntax
phparray_pop(array &$array): mixed
Example
Let's extract and output the last element of an array:
php<?php
$arr = [1, 2, 3, 4, 5];
echo array_pop($arr);
?>
Code execution result:
php5
The $arr array will now look like this:
php[1, 2, 3, 4]
See Also
-
the
array_shiftfunction,
which extracts the first element of an array