PHP Else If Condition Statement

What is Else If Structure?


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


if (expr 1)
elseif (expr2)//false

Based on the failure "expr1" condition, "expr2" is checked and then the statements are executed.

Example :

$c = 10;
$d = 10;
if ($c > $d)
echo "c is bigger than d";
elseif ($c==$d)
echo "c is equal to d";
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

PHP Topics

Ask Questions

Ask Question