We already discussed on simple if and if..else in this topic we discuss on elseif and nested if statement it also called inner if condition the following syntax and example of both type condition in php.
Use the if..elseif..else statement to select one of sevral blocks of code to be executed.the following syntax and example of elseif condition.
<?php
if(condition)
{
//Code to be Executed if Condition is True
}
elseif
{
//Code to be Executed elseif Condition is True
}
else
{
//Code to be Executed if Condition is False
}
?>
<?php
$a=20;
if($a<20)
{
echo "The Value of a is Less Than 20";
}
elseif($a>20)
{
echo "The Value of a is Greater Than 20";
}
else
{
echo "The Value of a is Equals to 20";
}
?>
Use the Nested if..else statement to select one of several blocks which also contains the selection of blocks nested it code to be executed.the following syntax and example of nested if.
<?php
if(condition)
{
if(condition)
{
//Code to be Executed elseif Condition is True
}
else
{
//Code to be Executed elseif Condition is False
}
}
else
{
if(condition)
{
//Code to be Executed elseif Condition is True
}
else
{
//Code to be Executed elseif Condition is False
}
}
}
?>
<?php
$a=5;
$b=10;
$c=20;
if($a>$b)
{
if($a>$c)
{
echo "Largest Value is $a";
}
else
{
echo "Largest Value is $c";
}
}
else
{
if($a>$b)
{
echo "Largest Value is $c";
}
else
{
echo "Largest Value $b";
}
}
?>