How to remove first element of an array PHP

If you have an array like this :

$fruits = ( "custard apple", "orange", "banana", "apple", "strawberry", "blueberry" );

You want to remove first element of an array that means you want array like this:
$fruits = ( "orange", "banana", "apple", "strawberry", "blueberry" );
 So just use array_shift() function like this


$shiftArray = array_shift($fruits);

Now your fruits array contains 5 elements :

print_r($friuts);
Custard apple is assigned to $shiftArray

Hope this article is helpful for you :)

Post a Comment

Analytics