PHP foreach loop
The foreach loop structure is a convenient way to loop through an array.
Syntax
<?php
foreach ($array as $value) {
code to be executed;
}
OR
foreach ($array as $key=>$value) {
code to be executed;
}
?>
Example
<?php
$array = array("1st" => "Orange", "2nd" => "Mango", "3rd" => "Grapes");
foreach ($array as $index => $var) {
echo $index . ": " . $var . "<br />";
}
#Output:
1st: Orange
2nd: Mango
3rd: Grapes
?>


