The php for loop is used when you know how many times the script should run the block of a code.
Example:
[php]<?php
for ($x = 5; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?> [/php]
In the above code, we have declared the value 5 to the variable $x
. Then we added the condition that the code should run until it matches the value 10. In final code, we are asking php script to increment the number from its variable value which is 5 till the condition value 10. The above will generate following output.
The number is: 5
The number is: 6
The number is: 7
The number is: 8
The number is: 9
The number is: 10