close[x]


PHP

PHP-Home PHP-Environment Setup PHP-Syntax PHP-Run PHP in XAMPP PHP-Variable PHP-Comment PHP-Datatype PHP-String PHP-Operators PHP-Decision PHP-loop PHP-Get/Post PHP-Do While loop PHP-While loop PHP-For loop PHP-Foreach loop PHP-Array PHP-Multidimensional Arrays PHP-Associative Arrays PHP-Indexed Arrays PHP-Function PHP-Cookies. PHP-Session PHP-File upload PHP-Email PHP-Data & Time PHP-Include & Require PHP-Error PHP-File I/O PHP-Read File PHP-Write File PHP-Append & Delete File PHP-Filter PHP-Form Validation PHP-MySQl PHP-XML PHP-AJAX



learncodehere.com




PHP - while Loop

The while statement will execute a block of code if and as long as a test expression is true.

If the test expression is true then the code block will be executed. After the code has executed the test expression will again be evaluated.


Syntax : while Loop


while (condition ) {
  code to be executed;
} 

Condition checks first, and then block of statements executes.

Let's put these syntax into real use.


Example : foreach Loop


<?php 
$x = 10; 
while ($x <= 20){
 echo "Number = $x <br>";
 $x++;
} 
?> 

This will produce the following result −

Result


 Number = 10
 Number = 11
 Number = 12
 Number = 13
 Number = 14
 Number = 15
 Number = 16
 Number = 17
 Number = 18
 Number = 19
 Number = 20