For each
 


The Foreach loop is a variation of the For loop and allows you to iterate over elements in an array. There are two different versions of the Foreach loop. The Foreach loop syntaxes are as follows:
foreach (array as value)
{
   code to be executed;
}
   
foreach (array as key => value)
{
   code to be executed;
}

The example below demonstrates the Foreach loop that will print the values of the given array:
$email = array('john.smith@example.com', 'alex@example.com');
foreach ($email as $value) {
   echo "Processing ".$value."
";
}
?>

PHP executes the body of the loop once for each element of $email in turn, with $value set to the current element. Elements are processed by their internal order. Looping continues until the Foreach loop reaches the last element or upper bound of the given array.