A for loop statement is a repetition of loop and it allows to efficiently write a loop that needs to be executed a certain number of times. For loops are useful in case of multi-dimensional arrays.
There are 3 statements at the start of the for loop viz. 1. Defining the incrementer 2. Setting the condition and 3. Incrementing the incrementer
Syntax
for (initialization counter; condition counter; increment counter) { //code to be executed; }
<?php for ($x = 1; $x <= 5; $x++) { echo $x; ?>
This will produce following result
1 2 3 4 5