ItSolutionStuff.com

How to Remove First Element from Array in PHP?

By Hardik Savani β€’ May 14, 2024
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: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

How to Push Element in Array in Node JS?

Read Now β†’
β˜…

How to get Keys from Array in PHP Laravel?

Read Now β†’
β˜…

PHP Remove Duplicates from Multidimensional Array Example

Read Now β†’
β˜…

How to Convert Object to Array in Laravel?

Read Now β†’
β˜…

How to Remove Specific Element by Value from Array in PHP?

Read Now β†’
β˜…

How to Remove undefined Value from Array in JQuery?

Read Now β†’
β˜…

How to Get Maximum Key Value of Array in PHP?

Read Now β†’
β˜…

How to Remove Empty Values from Array in PHP?

Read Now β†’
β˜…

How to Add Prefix in Each Key of PHP Array?

Read Now β†’
β˜…

How to Get Minimum Key Value of Array in PHP?

Read Now β†’
β˜…

How to Remove Null Values from Array in PHP?

Read Now β†’