PHP array_pop() Function Guide

The array_pop function is used to remove the last element from an array and return the deleted element.

Here is how you can use it:

$stack = array("orange", "banana", "apple");
$lastElement = array_pop($stack);
print_r($stack); // 输出:Array ( [0] => orange [1] => banana )
echo $lastElement; // 输出:apple

In the example above, we created an array $stack with three elements. We then used the array_pop function to remove the last element “apple” and assigned the deleted element to the variable $lastElement. Finally, we printed out the modified array $stack and the deleted element $lastElement.

It is important to note that the array_pop function will modify the original array by deleting the last element. If the array is empty, the function will return NULL.

bannerAds