This article mainly introduces the PHP process Control elseif/else If, has a certain reference value, now share to everyone, the need for friends can refer to
This paper tries to use the basic Learning Master, please close this page
Read this article for 3 minutes, it's hard to understand.
(PHP 4, PHP 5, PHP 7)
ElseIf, as implied by this name, is the combination of if and else. As with else, it extends the IF statement and can FALSE
execute different statements when the original if expression value is. But unlike else, it only executes the statement when the ElseIf's conditional expression value is TRUE
. For example, the following code will display a bigger than B,a equal to B , or A is smaller than Baccording to the conditions:
<?PHPIF ($a > $b) { echo "A is bigger than B";} elseif ($a = = $b) { echo "A is equal to B";} else { echo "A is smaller than B";}? >
There can be more than one ElseIf part in the same if statement, where TRUE
the ElseIf portion of the first expression value (if any) is executed. In PHP, you can also write "else if" (two words), which behaves exactly like "ElseIf" (a word). There is a slight difference in the meaning of syntactic analysis (if you are familiar with C, the same behavior), but the bottom line is that both produce exactly the same behavior.
The ElseIf statement only precedes the IF and all previous ElseIf expression values FALSE
, and the current ElseIf expression value is TRUE
executed.
Note: It must be noted that ElseIf and else if you use curly braces in a similar case, it is only considered identical. If you use a colon to define the If/elseif condition, you cannot use the else if for two words, or PHP will produce parsing errors.
<?php/* incorrect usage methods: */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 usage: */if ($a > $b): echo $a. "is greater than". $b; ElseIf ($a = = $b)://Note the ElseIf echo $a using a word . "Equals". $b; else: echo $a. "is neither greater than or equal to". $b; endif;? >
Related recommendations:
The else of PHP process Control
PHP Process Control if statement