It is recommended to use else if.
in PHP
(PHP 4, PHP 5)
ElseIf, as implied by this name, is the combination of if and else . As with else , it extends the if statement and can execute different statements when the original if expression FALSE
value is. But unlike else , it only executes the statement when the ElseIf 's conditional expression value is TRUE
.
It's important to note thatElseIfwith theelse ifIt is considered identical only if curly braces are used in a similar case. If you use a colon to defineif/ElseIfcondition, then you can't use two words.else if, or PHP will generate parsing errors
<?php
/* Incorrect method of use: */
if ($a>$b):
Echo$a."is greater than".$b;
else if ($a== $b): //will not compile
Echo"The above line causes a parse error.";
endif
/* Correct way to use: */
if ($a>$b):
Echo$a."is greater than".$b;
ElseIf ($a== $b): //Note the use of a word ElseIf
Echo$a."equals".$b;
Else
Echo$a."is neither greater than or equal to".$b;
endif
?>
The difference between ElseIf else if