|
foreachPHP4 (not PHP3) includes a foreach construct, much like perl and some other languages. This simply gives an easy way to iterate over arrays. There are two syntaxes; the second is a minor but useful extension of the first:
The first form loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one (so on the next loop, you'll be looking at the next element). The second form does the same thing, except that the current element's key will be assigned to the variable $key on each loop.
You may have noticed that the following are functionally identical:
Some more examples to demonstrate usages:
|
|||||||||||||||||||||
With any suggestions or questions please feel free to contact us |