Removing the Last Element of an Array in PHP


Use array_pop() to remove and return the last element of an array.

Source Code

$numbers = [1, 2, 3, 4, 5];
$lastNumber = array_pop($numbers);
echo "Removed: $lastNumber";
print_r($numbers);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments