Example 1 — Remove the Last Item
Pop one item from a small list.
<?php
$stack = [1, 2, 3];
$removed = array_pop($stack);
echo $removed, PHP_EOL;
echo implode(", ", $stack), PHP_EOL; How It Works
- Create a list. It holds 1, 2 and 3.
- Call array_pop(). It removes
3from the end. - Use the return value. The removed item is stored in
$removed. - Print the array. Only 1 and 2 are left.

