PHP Use Of Loops With Examples And Programming
\\ If you have any query or questions on my post, then please comment below //
Types Of PHP Loops:
Following are the loops of PHP:
1. If Statement.
2. If Else Statement.
3. If...Elseif....Else Statement.
4. Switch Statement.
If Statement:
This is used to check only one true condition.
Syntax Of If Statement:
if(test_condition)
{
Code, you want to execute, if true;
}
If Statement Program In PHP:
<?php
$a=10;
if($a==10)
{
echo"Number is equal to 10";
}
?>
If Else Statement:
This statement is used to check true and false condition, however here is only one test condition, we can write, that is on true block.
Syntax Of If Else Statement:
<?php
if(test_condition)
{
Code, you want to execute in True Block;
}
else
{
Code, you want to execute in False Block;
}
?>
Example Of If Else Statement In PHP:
<?php
$a=10;
if($a==10)
{
echo"Number is equal to 10";
}
else
{
echo"Number is not equal to 10";
}
?>
If...Elseif....Else Statement:
This is used where, we are having more than two test conditions.
Syntax:
<?php
if(test_condition)
{
Code, you want to execute according to above test condition;
}
else(test_condition)
{
Code, you want to execute according to above test condition;
}
else(test_condition)
{
Code, you want to execute according to above test condition;
}
else(test_condition)
{
Code, you want to execute according to above test condition;
}
else
{
Code, you want to execute according to above test condition;
} ?>