PHP Foreach Loop


PHP Foreach Loop

Examples using the foreach loop with PHP.

Loop Syntax #1

$items = array('one', 'two', 'three', 'four');
foreach ($items as $item) {
echo $item."<br/>";
}

Loop Syntax #2

$items = array('First' => 'one', 'Second' =>'two', 'Third' =>'three', 'Fourth' =>'four');
//This outputs the values
foreach ($items as $item) {
echo $item."<br/>";
}