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,和此名称暗示的一样,是 if 和 else 的组合。和 else 一样,它延伸了 if 语句,可以在原来的 if 表达式值为 FALSE 时执行不同语句。但是和 else 不一样的是,它仅在 elseif 的条件表达式值为 TRUE 时执行语句。例如以下代码将根据条件分别显示 a is bigger than b,a equal to b 或者 a is smaller than b:
在同一个 if 结构中可以有多个 elseif 语句。第一个表达式值为 TRUE 的 elseif 语句(如果有的话)将会执行。在 PHP 中,也可以写成“else if”(两个单词),它和“elseif”(一个单词)的行为完全一样。句法分析的含义有少许区别(如果你熟悉 C 语言的话,这是同样的行为),但是底线是两者会产生完全一样的行为。 elseif 的语句仅在之前的 if 或 elseif 的表达式值为 FALSE,而当前的 elseif 表达式值为 TRUE 时执行。
31-Jan-2007 10: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 05:59
The parser doesn't handle mixing alternative if syntaxes as reasonably as possible.
nospam at donireland dot com
26-Oct-2006 03:04
<?
jsimlo
15-Aug-2006 02:02
This example generates a parse error:
phpprogrammer at artspad dot net
11-Aug-2006 05: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
10-Apr-2005 03:44
Dont make your code as jumbled up as this: | |||