Simple php for loop instance, phpfor loop instance
The for loop is used to know the number of times the script needs to run in advance.
Syntax
For (initial value; condition; increment) {code to be executed ;}
Parameters:
• Initial Value:It mainly initializes a variable value for setting a counter (but it can be any code that is executed once at the beginning of the loop ).
• Condition:Restrictions on cyclic execution. If it is TRUE, the loop continues. If it is FALSE, the loop ends.
• Increment:It is mainly used for incremental counters (but can be any code executed at the end of the loop ).
Note: The preceding initial value and incremental parameter can be empty or have multiple expressions (separated by commas ).
The following instance 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. Every time a loop is run, 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 simple example of the above php for loop usage is all the content shared by xiaobian. I hope you can give us a reference and support the house of friends.