php while statement

You will give the While loop a condition to validate. As long as that condition is true, the code within the curly braces will be executed .

While loop Syntax

<?php
while (expression)
{
code to execute;
}
?>

While loop Example


<?php
$i = 1; // set counter
while ($i <= 100)
{
echo "$i";
$i++;
// increase counter by 1
}
?>

The Above code displays every number from 1 through 100 in a browser. It begins by setting a variable ($i) to 1, and then using the variable as a counter to control the loop, as well as display the current number onscreen.





Content