The number of times specified in the code block executed by the PHP loop continue, or if the specified condition is true.
-------------------------------------------------- ------------------------------
For loops
The loop is used when you know in advance how many times the script should run.
Grammar
for (init; condition; increment)
{
code to is executed;
}
Parameters:
Initialization: Primarily used to set a counter (but can be any code execution at the start of a loop)
Conditions: Evaluates each iteration of the loop. If the value is true, the loop continues. If the value is False, the loop ends.
Increment: Used primarily to add a counter (but can be any code that will execute at the end of the loop)
Note: The above can be empty, or there are multiple expressions for each argument (separated by commas).
For example
The following example defines a loop, which begins with i = 1. The loop will continue to run as long as I am less than or equal to 5. I'm going to add 1 each time the loop runs:
<body>
<?php
For ($i =1 $i <=5; $i + +)
{
echo "The number is". $i. "<br/>";
}
?>
</body>
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
Example Two
<?php
while (the list ($key, $value) = each ($arr)) {
if (!) ( $key% 2)) {//Skip odd members
Continue
}
Do_something_odd ($value);
}
$i = 0;
while ($i + + < 5) {
echo "Outer<br/>n";
while (1) {
echo " Middle<br/>n ";
while (1) {
echo " inner<br/>n";
Continue 3;
}
echo "This never gets output.<br/>n";
}
echo "Neither does this.<br/>n";
}
?>
<?php
for ($i = 0; $i < 5; + + $i) {
if ($i = = 2)
Continue
print "$in";
}
?>