The For loop is used in cases where you know in advance how many times the script needs to run.
Grammar
Parameters:
• Initial value: The primary is to initialize a variable value that sets a counter (but can be any code that is executed once at the beginning of the loop).
• Conditions: cyclic execution of restrictions. If true, the loop continues. If FALSE, the loop ends.
• Increment: used primarily for incrementing the counter (but can be any code executed at the end of the loop).
Note: The above initial and increment parameters can be empty, or there are multiple expressions (separated by commas).
The following example defines a loop with an initial value of I=1. As long as the variable i is less than or equal to 5, the loop continues to run. Each time the loop is run, the variable i increments by 1:
<?php for ($i =1; $i <=5; $i + +) {echo "the number is". $i. "
Output:
The above this PHP for loop use simple example is small series to share to everyone's content, hope to give you a reference, but also hope that we support the script home.