How to Remove First Element from Array in PHP?
This article goes in detailed on how to remove first element from array in php. you can understand a concept of remove first item from array in php. let’s discuss about php remove first element from array. We will use php remove first item from array. You just need to some step to done php remove first n element from array.
Let's see simple two example single dimensional array and multi dimensional array how to remove first item from array using php array function call array_shift(). array_shift() will helps to remove first key from php array.
Example 1:
index.php
<?php
$myArray = ["Apple", "Banana", "Mango"];
array_shift($myArray);
print_r($myArray);
?>
Output:
Array
(
[0] => Banana
[1] => Mango
)
Example 1:
index.php
<?php
$students = [
[ "id" => 1, "name" => "Hardik"],
[ "id" => 2, "name" => "Haresh"],
[ "id" => 3, "name" => "Naresh"],
];
array_shift($students);
print_r($students);
?>
Output:
Array
(
[0] => Array
(
[id] => 2
[name] => Haresh
)
[1] => Array
(
[id] => 3
[name] => Naresh
)
)
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 Push Element in Array in Node JS?
- How to get Keys from Array in PHP Laravel?
- PHP Remove Duplicates from Multidimensional Array Example
- How to Convert Object to Array in Laravel?
- 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?