While Loop Example In PHP
Php / / July 04, 2021
We have previously seen the While Loop Example in Javascript, now we will see a While Loop Example in PHP
The While Loop in PHP it is used to execute a piece of code as long as the condition is still true. They are generally used for counters, or to display records from a database.
In this example, the loop will end when the counter reached 10. We will do it through a variable called $ i, which is usually identified as a counter
Code:
#Example of. COM
#Example of While Loop in PHP
$ i = 0; // We initialize the variable at 0
while ($ i == 10) {
$ i ++; // We increase $ i by one
echo "i now equals". $ i. "
"; // We show text
}
echo "End of while loop. The while loop ended in ". $ I." ";
?>
This example will show the following
Code:
i now equals 1
i now equals 2
i now equals 3
i now equals 4
i now equals 5
i now equals 6
i now equals 7
i now equals 8
i now equals 9
i now equals 10
End of while loop. The while loop ended in 10