PHP Else If Condition Statement
What is Else If Structure?
Explanation
else if statement is used as extension of "If" structure if the condition fails then it executes another "If" condition to execute the code segment under the "else if" statement
Syntax:
if (expr 1)
{Statements}//true
elseif (expr2)//false
{Statements}//true
else
{Statements}//false
Based on the failure "expr1" condition, "expr2" is checked and then the statements are executed.
Example :
<?php
$c = 10;
$d = 10;
if ($c > $d)
{
echo "c is bigger than d";
}
elseif ($c==$d)
{
echo "c is equal to d";
}
else
{
echo "d is smaller than c";
}
?>
Result :
c is equal to d
In the above example the if the condition "$c>$d" is true then the message "c is bigger than d" is displayed, else the condition in the else if that is "$c==$d" is evaluated if it is true the message "c is equal to d" is displayed otherwise "d is smaller than c" is displayed