PHP For Loop

The for loop is used to execute a block of code for a specified number of times.

Syntax

for (init; condition; increment) {
    // code to be executed
}

Example of PHP For Loop

<?php
for ($i = 0; $i < 5; $i++) {
    echo "The number is $i\n";
}
?>

Output:

The number is 0
The number is 1
The number is 2
The number is 3
The number is 4

Explanation: This example demonstrates the use of the for loop in PHP. The loop executes 5 times, and the value of $i is printed each time.