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, 1, 2, 3, 4, 5); print_r("Array after multiple insertions </br>"); print_r($arr); array_pop($arr); // Single array pop print_r("Array after a single pop </br>"); print_r($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 - The PHP array_pop function removes and returns the last element of an array.
🌐
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
connection_aborted() connection_status() connection_timeout() constant() define() defined() die() eval() exit() get_browser() __halt_compiler() highlight_file() highlight_string() hrtime() ignore_user_abort() pack() php_strip_whitespace() show_source() sleep() sys_getloadavg() time_nanosleep() time_sleep_until() uniqid() unpack() usleep() PHP MySQLi · affected_rows autocommit change_user character_set_name close commit connect connect_errno connect_error data_seek debug dump_debug_info errno error error_list fetch_all fetch_array fetch_assoc fetch_field fetch_field_direct fetch_fields fetch_l
🌐
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 of Array instances removes the last element from an array and returns that element. This method changes the length of the array.
🌐
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.