foreach
Iterates over each element of the array.
Syntax
foreach ($arr as $element) { }Description
Processes array/associative array elements in order. With key: foreach ($d as $k => $v).
Example
Loading editor…
Expected output
red purple
When to use?
Array processing (PHP's most used loop).