PHP while loop statement allows to repeatedly run the same block of code until a condition is met.



Syntax:

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

php-while

Example:

<?php 
$i = 1; 

while ($i <= 5){ 
  echo "Hello while $i times"."<br>"; 
  $i++; 
} 
?>

Program Output:

Hello while 1 times

Hello while 2 times

Hello while 3 times

Hello while 4 times

Hello while 5 times


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram