Loop Statement – foreach
The foreach loop is mostly used to parse through an array that for every loop, the value of the current array content/value is assigned to the $value (after which the array pointer increments by a factor of one) then the next loop results in the next array content/value.
Syntax:
foreach (array as value)
{
code to be executed;
}
Sample :
The sample below would show a loop to print verbosely the contents of a given array.
$a=array("three", "two", "one");
foreach ($arr as $value)
{
echo "Value: ". $value . "
“;
}
?>
Filed under: Basic Programming, Sample Code by Celine
