PHP » Arrays » array_pop()

Syntax:
mixed array_pop(array array)
array
The array to be popped.

Removes and returns one element off the end of an array.

array_pop() removes an element off the end of an array. The removed element is returned.

An array can be used as a stack by using array_push() and array_pop() together.

Examples

Code:
<?php

$array1 = array("one", "two", "three");

foreach ($array1 as $element)
   print "$element ";
print "<br>" . array_pop($array1) . "<br>";
foreach ($array1 as $element)
   print "$element ";

?>
Output:
one two three
three
one two
Explanation:

This code shows the results of popping an array.

See Also: