if...elseif....else statement:
Else..if condition allows users to check more than one condition. That means if the condition is false it allows to check with another condition. So this statement contains more if and else statements.
Syntax is:
<?php
If(condition1) {
Statement1;
} else if(condition2) {
Statement2;
} else if(condition3) {
Statement3;
} else Statement4;
?>
In above syntax,
- if the condition1 is true then statement1 is executed.
- if the condition2 is true then statement2 is executed.
- if the condition3 is true then statement3 is executed.
- If all conditions are false then statement4 is executed.
Let us see the program ,
Find biggest number among three numbers.
Biggest Number
<?php
$a = 6;
$b = 7;
$c = 4;
if(($a>$b)&&($a>$c)) {
echo "a is big number";
} else if(($b>$a)&&($b>$c)) {
echo "b is big number";
} else if(($c>$a)&&($c>$b)) {
echo "c is big number";
}
?>
Output: b is big number