array each ( array &$array_variable );
each function does the following tasks:
- It copies the current element’s key and value pair out of the
- It creates a new four element array and the assigns:
$array_variablekey to both keys 0 and key
$array_variablevalue to both keys 1 and value.
- Then it moves the array’s internal pointer to the next element in the array.
- Then it returns the new array.
- The array to be worked on by
It returns a four element array which has both the key (keyed by ‘0’ and ‘key’) and value (keyed by ‘1’ and ‘value’). It returns
FALSE when either the $array_variable is empty or it’s internal pointer is out-of-bounds and not pointing to a valid element.
Show It in ActionBasic
Let’s see the
each function in action. In this video, you will see how it works.
When was the last time you got out of your chair and stretched? Just saying…
In this video, you will go deeper into the instruction.
When do you use a
each versus a
The following PHP constructs were mentioned in the code examples: