PHP While Loop

PHP while loop is used to run the same block of code until a condition is met. It should be used if number of iteration it not known.

Syntax:

<?php
while (condition){
  //Code to be executed;
}
?>

Example:

<?php
$n= 1;
while($n<=5){
echo "$n<br/>"
$n++;
}
?>

Output

1

2

3

4

5



ADVERTISEMENT
ADVERTISEMENT