PHP while Keyword
Example
Use a while
loop to print numbers from 1 to
5:
<?php
$i = 1;
while($i <= 5) {
echo $i;
echo "<br>";
$i++;
}
?>
Try it Yourself »
Definition and Usage
The while
keyword is used to create a while
loop and is also used to set the looping
condition of a do...while
.
Related Pages
The do
keyword.
Read more about while loops in our PHP while Loop Tutorial.
Read more about do...while loops in our PHP do while Loop Tutorial.
❮ PHP Keywords