PHP tutorial for beginners, This lessons will show you how we can use more loops in PHP, How Does PHP While Do-While For & Foreach Loops Works???
Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types.
- FOR − loops through a block of code a specified number of times.
- WHILE − loops through a block of code if and as long as a specified condition is true.
- DO...WHILE− loops through a block of code once, and then repeats the loop as long as a special condition is true.
- FOREACH − loops through a block of code for each element in an array.
Video Tutorial How Does PHP While Do-While For & Foreach Loops Works???
PHP FOR LOOP
<?php
for ($i=0; $i < 10; $i++) {
echo "loops $i </br>";
}
?>
PHP DO-WILE LOOP
<?php
$a = 0;
do {
echo "Loops $a </br>";
$a++;
} while ($a <= 10);
echo "Loops end";
?>
PHP WHILE LOOP
<?php
$a = 0;
while ($a <= 10) {
echo "Loops $a <br>";
$a++;
}
?>
PHP FOREACH
<?php
$a = array(0,1,2,3,4,5,7,8);
foreach ($a as $key => $value) {
echo "Loops $value <br>";
}
?>
See you next lessons ...
Không có nhận xét nào:
Đăng nhận xét