The foreach loop is used to loop through arrays.
Syntax:
foreach ($array as $value)
{
code to be executed;
}
For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one - so on the next loop iteration, you'll be looking at the next array value.
Example:
<html>
<body>
<?php
$x=array("one","two","three");
foreach ($x as $value)
{
echo $value . "<br>";
}
?>
</body>
</html>
Output:
one
two
three