This inbuilt function of PHP removes the first element from an array and returns the value of the removed element. After the removal of the first element, the key of the remaining elements is modified and again re-numbered from the start, only if the keys are numerical. In other words, this function basically shifts an element off from the begining in an array.
Parameters: The function takes only one argument, $array which refers to the original input array which needs to be shifted.
Return Value: As already mentioned, the function returns the value of the shifted element from the array, otherwise NULL if the array is empty.
Input : $array = ("ram"=>2, "aakash"=>4, "saran"=>5, "mohan"=>100) Output : 2 Input : $array = (45, 5, 1, 22, 22, 10, 10); Output :45
In this program, we will see how the function works in key_value pair array.
2 Array ( [aakash] => 4 [saran] => 5 [mohan] => 100 )
Now let’s see how the function takes care of the default key.
45 Array (  => 5  => 1  => 22  => 22  => 10  => 10 )
This article is attributed to GeeksforGeeks.org