How to use array_shift() Function in PHP

array_shift function is used to shift or remove the first value of an array.

Here’s an example :

Output will look like this :

Array ( [0] => The Doors [1] => Dire Straits [2] => Simon and Garfunkel )

The first value from the array is removed. You can assign the removed value to a new variable like this :

$NewVariable = array_shift($bands);

This variable contains values from the array except the one you removed using the function.

Click Here to Leave a Comment Below

Leave a Reply: