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
array_pop() pops and returns the value of the last element of array, shortening the array by one element. Note: This function will reset() the array pointer of the input array after use.
🌐
W3Schools
w3schools.com › php › func_array_pop.asp
PHP array_pop() Function
Loops While Loop Do While Loop For Loop Foreach Loop Break Statement Continue Statement PHP Functions PHP Arrays
People also ask

What happens if you use array_pop on an empty array?
It returns NULL if the array is empty. here is an example:
$array = []; 
$removed = array_pop($array); 
var_dump($removed); 
🌐
flatcoding.com
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 - ...
How to get the last element of a PHP array?
You can use the array_pop to get the last item in an array. Here is an example:
$array = [10, 20, 30, 40, 50]; 
$last = array_pop($array);
echo $last;
🌐
flatcoding.com
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 - ...
How to remove the last element of a PHP array?
You can remove it with array_pop:
$array = [10, 20, 30, 40]; 
$removed = array_pop($array); 
echo $removed; 
print_r($array); 
This removes and returns the last item.
🌐
flatcoding.com
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 - ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-use-array_pop-and-array_push-methods-in-php
How to use array_pop() and array_push() methods in PHP ? - GeeksforGeeks
July 23, 2025 - Parameters: The function takes only one parameter $array, that is the input array, and pops out the last element from it, reducing the size by one. ... <?php // Declaring an array $arr = array(); // Adding the first element array_push($arr, ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-array_pop-function
PHP array_pop() Function - GeeksforGeeks
June 20, 2023 - This inbuilt function of PHP is used to delete or pop out and return the last element from an array passed to it as parameter. It reduces the size of the array by one since the last element is removed from the array.
Find elsewhere
🌐
W3docs
w3docs.com › learn-php › array-pop.html
PHP Array Pop: The Ultimate Guide
PHP Array Pop is a built-in function in PHP that allows you to remove the last element from an array and return it.
🌐
Narod
pyramidin.narod.ru › array-pop.html
array_pop
array_pop - выталкивает последний элемент массива.Описаниеmixed array_pop (array array) · array_pop() возвращает последнее значение массива array, укорачивая array на один (этот) элемент.
🌐
ZetCode
zetcode.com › php-array › array-pop
PHP array_pop - Remove Last Array Element in PHP
March 13, 2025 - Syntax: array_pop(array &$array): mixed. The function takes an array by reference and modifies it directly. The array's length decreases by 1. This demonstrates removing the last element from a simple numeric array. ... <?php $fruits = ['apple', 'banana', 'cherry']; $lastFruit = array_pop($fruits); ...
🌐
Envato Tuts+
code.tutsplus.com › home › coding fundamentals
Pop and Shift Arrays With PHP: When to Use Each One | Envato Tuts+
December 31, 2021 - There is a dedicated function called array_pop() to help you pop an element off the end of a given array in PHP.
🌐
W3Schools
w3schools.com › php › php_ref_array.asp
PHP Array Functions
Loops While Loop Do While Loop For Loop Foreach Loop Break Statement Continue Statement PHP Functions PHP Arrays
🌐
Dev Lateral
devlateral.com › home › guides › php › how does array_pop work in php
How does array_pop work in PHP | Dev Lateral
May 14, 2024 - Array pop or array_pop() as it will be typically written in PHP code takes an array of data and returns back the last item in the array, whilst removing it from the array itself, therefore shortening the array by one element.
🌐
W3Schools
w3schools.com › php › php_arrays_remove.asp
PHP Remove Array Items
The array_pop() function removes the last item of an array.
🌐
Codecademy
codecademy.com › docs › php › arrays › array_pop()
PHP | Arrays | array_pop() | Codecademy
July 8, 2023 - The array_pop() method removes the last element of an array, and returns the truncated array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › pop
Array.prototype.pop() - JavaScript | MDN
The pop() method is a mutating method. It changes the length and the content of this. In case you want the value of this to be the same, but return a new array with the last element removed, you can use arr.slice(0, -1) instead.
🌐
OnlinePHP
onlinephp.io › array-pop › manual
array_pop - OnlinePHP.io Example
array_pop pops and returns the value of the last element of array, shortening the array by one element.