The What
Description
The 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.
Parameters
array_variable
- The array to be worked on by
array_shift
.
Return Values
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.
Hands off the keyboard. Web development starts by thinking first, then planning it out, and then coding it.
Go DeepPro
In this video, you will go deeper into the instruction.
WhenPro
Also See
The following PHP constructs were mentioned in the code examples: