PHP

How To Remove The First Element From An Array In PHP1 min read

You can use the PHP array_shift() function remove the first element from an array in PHP. The array_shift() function returns the first value of the array. If array is empty or is not an array then NULL will be returned.

PHP array_shift() Function Syntax

First let’s see the $stack array output :




Output:

$stack array have 5 elements and we want to remove the first element has value “yellow”.

Remove the First element from an array

Now we will use PHP array_shift() function to remove first element of an array like in below example

Output:

and “yellow” will be assigned to $removed.

Output:

Leave a Comment