Backend Development 2 min read

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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP array_pop() – Popping the Last Element from an Array

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
)
backendPHPphp-functionsarray-manipulationarray_pop
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.