PHP for loop
A for loop is used to execute the program for a fixed number of times. For loop in PHP is similar to that in C, C++ or Java.
A for loop has three parts.
- Condition and
- An operation to be performed each time the loop is executed.
for($i=0; $i<10; $i++)
This is how a for loop works:
- A value is initialized (only for the first time).
- An expression is evaluated.
- The body of the loop is executed if the expression is evaluated to true.
- An operation (increment or decrement) is performed.
- The above three steps are repeated until the expression is evaluated to false.
See this post to find the difference between a for loop and while loop.
for($i=0; $i<=2; $i++)