How to Remove First Element from Array in PHP?

By Hardik Savani November 5, 2023 Category : 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...

Tags :
Shares