for LoopThe syntax of a forloop is:
for (expr1; expr2; expr3)
statement
We can group several statements into a statement group
for (expr1; expr2; expr3){
statement1;
statement2;
}
<?php
for($i=1; $i<3; $i++){
echo "i = $i <br>";
}
var_dump($i);
?>
Output:
i = 1 i = 2 int(3)
For loop statementPHP also supports the alternate "colon syntax" for for loops.
<?php
for($i=1; $i<3; $i++):
echo "i = $i <br>";
endfor;
?>
