foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects
Below the two syntaxes of foreach loop:
foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects
Below the two syntaxes of foreach loop:
<?php
$array = array('One', 'Two', 'Three', 'Four', 'Five');
foreach ($array as $item)
{
echo "$item<br />";
}
?>
Output:
One Two Three Four Five
<?php
$array = array('One', 'Two', 'Three', 'Four', 'Five');
foreach ($array as $key => $item)
{
echo "$key = $item<br/>";
}
?>
Output:
0 = One 1 = Two 2 = Three 3 = Four 4 = Five