Web EndMemo

PHP For Loop


For example, add 1 to 100 up:
<?PHP
$sum = 0;
for ($ii=1; $ii<100; $ii++)
{
    $sum += $ii;
}
echo "$sum";
?>


Also, function foreach() can be used to iterate through an array:
<?PHP
$arr = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
foreach($arr as $d)
{
    echo "$d\n";
}
?>


For associated array:
<?PHP
$arr = array("one"=>"Monday","two"=>"Tuesday","three"=>"Wednesday",
"four"=>"Thursday","five"=>"Friday","six"=>"Saturday","seven"=>"Sunday");
foreach($arr as $num=>$d)
{
    echo "$num, $d\n";
}
?>