foreach Loop in PHP

The foreach loop is used to iterate over arrays.

Syntax :
foreach (array as value)
{
      code to be executed;
}

Example :
<?php
$array = array( 1, 2, 3, 4, 5);
foreach( $array as $value )
{
echo "Value is $value <br />";
}
?>

Output :
Value is 1
Value is 2
Value is 3
Value is 4
Value is 5

0 Comments