How to Remove Array Last Element in PHP?
Nov 26, 2022
Hi Dev,
In this article, to remove the last element or value from an array, array_pop() function is used. this function returns the last removed element of the array and returns null if the array is empty, or is not an array
There are example to check if Remove Array Last Elementin php. in this example, we will use to array_pop() function to check if how to Remove Array Last Element in PHP. so let's the following example with output.
Example 1:
index.php
<?php
$car = array("Mercedes", "Creta", "Audi", "Chevrolet", "Skoda");
echo "Arraylist: ";
print_r($car);
$remove = array_pop($car);
echo "</br>Removed element from array is: ";
print_r($remove);
echo "</br>Updated arraylist: ";
print_r($car);
?>
Output:
Arraylist: Array ( [0] => Mercedes [1] => Creta [2] => Audi [3] => Chevrolet [4] => Skoda )
Removed element from array is: Skoda
Updated arraylist: Array ( [0] => Mercedes [1] => Creta [2] => Audi [3] => Chevrolet )
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example