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
array_pop(array &$array): mixed
Example
Let's extract and output the last element of an array:
<?php
$arr = [1, 2, 3, 4, 5];
echo array_pop($arr);
?>
Code execution result:
5
The $arr
array will now look like this:
[1, 2, 3, 4]
See Also
-
the
array_shift
function,
which extracts the first element of an array