A For loop is used when you know in advance how many times a script needs to run.
Grammar
for (initial value; condition; increment)
{
code to execute;
}
Parameters:
• Initial value: primarily initializes a variable value that is used to set a counter (but can be any code that executes once at the beginning of the loop).
• Condition: The restriction condition for circular execution. If TRUE, the loop continues. If FALSE, the loop ends.
• Increment: primarily for incrementing counters (but can be any code that executes at the end of the loop).
Note: The above initial and incremental parameters can be empty or have multiple expressions (separated by commas).
The following instance defines a loop with an initial value of I=1. The loop continues to run as long as the variable i is less than or equal to 5. Each time the loop is run, the variable i increments by 1:
<?php for
($i =1 $i <=5; $i + +)
{
echo "the number is". $i. "<br>";
>
Output:
The number is 1 the number is 2 the number is 3 the number is 4 the number is
5
The above PHP for the use of a simple example is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.