Jun 15, 2021
.
Admin
Hi guys,
Today i will explained how to use php loop in your php file. This example is so easy to use in php. THis example to i am use in many looping statement use in example.
This example to i am use in while loop,do..while loop,for loop,and foreach looping statement used in this tutorial. So you are follow for my step by step.
So let's start to the example.
While Loop
The while loop executes a block of code as long as the specified condition is true.
<?php
$while = 1;
while($while <= 5){
echo "while Loop Number Is : $while <br>";
$while++;
}
?>
Do...While Loop
The do..while loop is always execute the block of code in once ,and then check the condition and repeat the loop in spacificed condition is true.
<?php
$do_while = 1;
do{
echo "Do while Loop Number Is : $do_while <br>";
$do_while++;
}while($do_while <= 5);
?>
For Loop
For loop through a block of code is run in many time to execute.
<?php
for ($x = 0; $x <= 100; $x+=10) {
echo "For Loop number is: $x <br>";
}
?>
Foreach Loop
Foreach loop is used in only array value and use to the key and value pairs in array.
<?php
$user = ["Id"=>"1", "Name"=>"Velgi", "Age"=>"35"];
foreach($user as $key => $value) {
echo "$key = $value <br>";
}
?>
now you can check your own.
i hope it can help you...
#PHP 8
#PHP