How to Remove Last Element from Array in PHP?
This example is focused on how to remove last element from array in php. We will look at example of remove last item from array in php. if you want to see example of php remove last element from array then you are a right place. i would like to show you php remove last item from array. Let's see bellow example php remove last n element from array.
Let's see simple two example single dimensional array and multi dimensional array how to remove last item from array using php array function call array_pop(). array_pop() will helps to remove last key from php array.
Example 1:
index.php
<?php
$myArray = ["Apple", "Banana", "Mango"];
array_pop($myArray);
print_r($myArray);
?>
Output:
Array
(
[0] => Apple
[1] => Banana
)
Example 1:
index.php
<?php
$students = [
[ "id" => 1, "name" => "Hardik"],
[ "id" => 2, "name" => "Haresh"],
[ "id" => 3, "name" => "Naresh"],
];
array_pop($students);
print_r($students);
?>
Output:
Array
(
[0] => Array
(
[id] => 1
[name] => Hardik
)
[1] => Array
(
[id] => 2
[name] => Haresh
)
)
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Reset Array Keys in PHP?
- Laravel 5 manual pagination with array example
- How to Remove Specific Element by Value from Array in PHP?
- How to Remove undefined Value from Array in JQuery?
- How to Get Maximum Key Value of Array in PHP?
- How to Remove Empty Values from Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Remove Null Values from Array in PHP?
- How can Make an Array from the Values of Another Array's Key Value?
- How to Merge Two Array with Same Keys without Loop in PHP?