PHP do…while Loop
The do-while
loop is a variant of while loop, which evaluates the condition at the end of each loop iteration. With a do-while
loop the block of code executed once, and then the condition is evaluated, if the condition is true, the statement is repeated as long as the specified condition evaluated to is true.
do{
// Code to be executed
}
while(condition);
<?php
$i
=
1;
do{
$i++;
echo
"The number is "
.
$i
.
"<br>";
}
while($i
<=
3);
?>
PHP foreach Loop
The foreach
loop is used to iterate over arrays.
foreach($array as $value){
// Code to be executed
}
The following example demonstrates a loop that will print the values of the given array:
<?php
$colors
=
array("Red",
"Green",
"Blue");
foreach($colors
as
$value){
echo
$value
.
"<br>";
}
?>
NEXT phpcheckbox