Need a Website Or Web Application Or Any Help In Code , Contact Us: +91 9437911966 (Whatsapp), Note: Paid Service
Students Tutorial app relased. Download Now.

PHP while loops

In PHP while loops is used to execute a block of code while the specified condition is true.

Some time we want the same block of code to run over and over again.

Example: Print 1 to 10 number.

Example: Fetch multiple students data.In that case we can use while loop.


while (condition is true) {
    code to be executed;

Example(Print 1 to 10)

while ($a<=10)
echo $a;

Run It Yourself »

Example(Print all even and odd number between 0 to 10)

     while($i <= 10){
         if($i % 2 == 0){
             echo $i." - Even,  ";
              echo $i." - Odd,  ";

Run It Yourself »