mixed array_shift ( array &$array_variable );
array_shift function does the following tasks:
- It checks if the variable is an array and it’s not empty. If no, it returns null.
- Copies the first element of out the array.
- It deletes the first element out of the array.
- It reindexes numerical keys (not literal ones).
- Then it does a
reset, which moves the array’s internal pointer to the first element in the array.
- Then it returns the copied element.
- The array to be worked on by
It returns the first element’s value (not the key) when the array is not empty. Else it returns
FALSE when each of the variables passed into the instruction meet the checks listed above.
Show It in ActionBasic
Let’s see the
array_shift function in action. In this video, you will see how it works.
Break. Go rest your noodle for a couple of minutes.
In this video, you will go deeper into the instruction.
The following PHP constructs were mentioned in the code examples: