Example of php for loop usage, php 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: Initializes a variable value to set 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.
- Incremental: It is mainly used for incremental counters (but can be any code executed at the end of the loop ).
Note:The aboveInitial ValueAndIncrementalThe parameter can be null or multiple expressions (separated by commas ).
The following instance defines a loop with an initial value of I = 1. As long as the variableIIf the value is less than or equal to 5, the loop continues to run. Every time a loop is run, the variableIIt will increase by 1:
<?phpfor ($i=1; $i<=5; $i++){echo "The number is " . $i . "<br>";}?>
Output:
The number is 1The number is 2The number is 3The number is 4The number is 5
Address: http://www.manongjc.com/php/php_while.html
Related reading:
Php strtok () usage-php strtok () function example
Difference between strtok () and explode () in php string segmentation Function
Php strtr () string replacement function Usage Analysis
Php substr () intercepts the specified length of the substring from the specified position of the string