while loop in php

The simplest kind of loop in PHP is the while loop. Like an if statement, it relies on a condition. The difference between a while loop and an if statement is that an if statement executes the code that follows it only once if the condition is true. A while loop executes the block repeatedly for as long as the condition is true


while( condition ) expression;

Example of while loop

$num = 1;
while ($num <= 5 ){
 echo $num."<br />";

Leave a Comment