PHP While Loop
The while loop is used to execute a block of code while a condition is true.
Syntax
while (condition) {
// code to be executed
}
Example of PHP While Loop
<?php
$i = 0;
while ($i < 5) {
echo "The number is $i\n";
$i++;
}
?>
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 while loop in PHP. The loop executes 5 times, and the value of $i is printed each time.