There is no good way to interpret the dangling else. One must pick a way and apply rules based on that.
Since there is no endif before an else, there is no easy way for PHP to know what you mean.
![]() |
|
||||||||||
|
elseifelseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE. For example, the following code would display a is bigger than b, a equal to b or a is smaller than b:
There may be several elseifs within the same if statement. The first elseif expression (if any) that evaluates to TRUE would be executed. In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word). The syntactic meaning is slightly different (if you're familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior. The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to FALSE, and the current elseif expression evaluated to TRUE. elseif
31-Jan-2007 02:54
There is no good way to interpret the dangling else. One must pick a way and apply rules based on that.
Vladimir Kornea
27-Dec-2006 09:59
The parser doesn't handle mixing alternative if syntaxes as reasonably as possible.
nospam at donireland dot com
25-Oct-2006 08:04
<?
jsimlo
15-Aug-2006 07:02
This example generates a parse error:
phpprogrammer at artspad dot net
10-Aug-2006 10:58
The comment critizing matheo's code while making some perhaps interesting statements about code efficiency missed the point completely.
mega0m3ga at yahoo dot com
09-Apr-2005 08:44
Dont make your code as jumbled up as this: |