while
while loop is a simple type of loop in PHP. It behaves just like in C language. The following is a basic while statement:
while (expr) statement
The meaning of this while statement is very simple. It tells PHP to execute statement(s) repeatedly as long as the while expression evaluates to true. The value of the expression is checked at the beginning of each loop. If the value of the expression is changed during execution, the program will end after evaluating the contents of the iteration. Sometimes, if the expression evaluates to FALSE from the beginning, the statement(s) will not be executed even once.
Like if statements, you can use curly braces to group multiple statements together. or by using the alternate syntax:
while (expr): statement ... endwhile;
The following two examples are the same, both output 1 to 10:
/* example 1 */$i = 1;while ($i