PHP array_pop() – Popping the Last Element from an Array
This article explains PHP's array_pop() function, describing its behavior, parameters, return value, and provides a complete example that demonstrates how the function removes the last element from an array and what output is produced.
The array_pop() function in PHP removes and returns the last element of an array, decreasing the array's length by one.
If the supplied argument is not an array or the array is empty, the function returns NULL and may emit a warning.
Parameter: $array – the array from which the last element will be popped.
Return value: The value of the last element of the array, or NULL if the array is empty or not an array.
Example:
<?php
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_pop($stack);
print_r($stack);
?>Output:
Array
(
[0] => orange
[1] => banana
[2] => apple
)Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.