if(empty($transport[count($transport)-1])) {
    unset($transport[count($transport)-1]);
}
Answer from Scott Saunders on Stack Overflow
🌐
PHP
php.net › manual › en › function.array-pop.php
PHP: array_pop - Manual
What would be wrong with: <?php $array = array('one', 'two', 'three', 'four'); //pop the last element off array_pop($array); //$array == array('one', 'two', 'three'); ?> As the documentation clearly notes, array_pop() not only returns the last element, but actually removes it from the array wich is passed by reference.
🌐
W3Schools
w3schools.com › php › func_array_pop.asp
PHP array_pop() Function
The array_pop() function deletes the last element of an array. array_pop(array) ❮ PHP Array Reference · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS · BOOTCAMPS · CONTACT US · × ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-remove-last-element-from-an-array-in-php
How to Remove Last Element from an Array in PHP ? - GeeksforGeeks
July 23, 2025 - The array_pop() function is specifically designed to remove the last element from an array and return its value. ... <?php $arr = [1, 2, 3, 4, 5]; // Remove last element using // array_pop() function $lastElement = array_pop($arr); // Display ...
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-remove-the-last-element-from-an-array-in-php.php
How to Remove the Last Element from an Array in PHP
You can use the PHP array_pop() function to remove an element or value from the end of an array. The array_pop() function also returns the last value of array.
🌐
W3Schools
w3schools.com › php › php_arrays_remove.asp
PHP Remove Array Items
In PHP, you can remove/delete array ... specific key · array_diff() - remove items from an associative array · array_pop() - removes the last array item ·...
🌐
ZetCode
zetcode.com › php-array › array-pop
PHP array_pop - Remove Last Array Element in PHP
March 13, 2025 - The PHP array_pop function removes and returns the last element of an array. It reduces the array length by one and returns the removed value. The array_pop function removes the last element from an array.
Find elsewhere
🌐
FlatCoding
flatcoding.com › home › php array_pop: remove and return the last element of an array
PHP array_pop: Remove and Return the Last Element of an Array - FlatCoding
August 19, 2025 - The array_pop function in PHP gives you a direct way to take the last element from an array. ... The array_pop in PHP removes the last value from an array.
🌐
GeeksforGeeks
geeksforgeeks.org › php › remove-an-elements-from-end-of-an-array-in-php
Remove an Elements From End of an Array in PHP - GeeksforGeeks
July 23, 2025 - We are going to use the unset() function in the PHP arrays which are the ordered maps and use the integer keys starting from 0. To remove an element from the end of an array using unset(), we specify the index of the last element in the array.
🌐
Sentry
sentry.io › sentry answers › php › deleting elements from an array in php
Deleting elements from an array in PHP | Sentry
The unset() function, which removes the element by its key and removes the element’s index. The array_splice() function is the most versatile and direct solution for deleting an element from both indexed arrays and associative arrays (with ...
🌐
PHPBuilder
board.phpbuilder.com › d › 10283821-resolved-resolved-delete-last-element-of-an-array
[Resolved] [Resolved] delete last element of an array - PHPBuilder Forums
August 25, 2004 - I have an array that always ends up with 1 blank entry at the end. What's the most efficient way of deleting the last element of an array? The only way I c...
🌐
TecAdmin
tecadmin.net › remove-last-element-from-array-in-php
Removing the Last Element from an Array in PHP – TecAdmin
April 26, 2025 - The `array_pop()` function in PHP is used to delete or remove the last element from an array. Not only does it remove the last element, but it also returns the value of the removed element.
🌐
Reactgo
reactgo.com › home › remove the last n elements from an array in php
Remove the last n elements from an array in PHP | Reactgo
October 24, 2022 - In PHP, array are collection of ... To remove the last n elements from an array, we can use the built-in array_slice() function by passing $array, 0, -$n as an arguments....
🌐
PHP Tutorial
phptutorial.net › home › php tutorial › php array_pop
PHP array_pop() Function
April 6, 2025 - In this example, the array_pop() function remove the last element of the $scores array regardless of the key. It returns the value of that element, which is "C". Use the PHP array_pop() function to remove the last element of an array.
🌐
Studytonight
studytonight.com › php-howtos › how-to-remove-last-element-from-an-array-in-php
How to remove last element from an array in PHP? - Studytonight
August 5, 2021 - We can remove the last element from an array using the array_pop() function. This function takes an array as its input and returns the last array element, which is being removed.