PHP array_pop: Remove Last Element from Array

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

Here is the sample code:

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

In the above example, the array_pop function removed the last element “orange” from the array $fruits and returned the deleted element “orange”. The print_r function is used to print the remaining array elements, which outputs Array ( [0] => apple [1] => banana ). The echo statement outputs the deleted element “orange”.

bannerAds