是"elseif"和"else if"完全同义? [英] Are "elseif" and "else if" completely synonymous?

查看:101
本文介绍了是"elseif"和"else if"完全同义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

elseifelse if是完全同义的,还是有区别?

Are elseif and else if completely synonymous, or is there a difference?

Zend是否有接受使用的标准"?

Does Zend have an accepted "standard" on which one to use?

虽然我个人不喜欢在代码中看到elseif,但我只需要知道它们是否是同义词,并且PHP手册不是最容易搜索的.

While I personally dislike seeing elseif in the code, I just need to know if they're synonymous and the PHP manual isn't the easiest to search.

推荐答案

来自

在PHP中,您还可以编写"else if"(用两个词表示),其行为与"elseif"之一(用一个词表示)相同.语法含义略有不同(如果您熟悉C,这是相同的行为),但最重要的是,两者都将导致完全相同的行为.

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.

从本质上讲,它们的行为相同,但是else if在技术上等效于如下嵌套结构:

Essentially, they will behave the same, but else if is technically equivalent to a nested structure like so:

if (first_condition)
{

}
else
{
  if (second_condition)
  {

  }
}

该手册还指出:

请注意,如上例所示,使用大括号时,elseif和else if仅被视为完全相同.使用冒号定义if/elseif条件时,请勿将else分隔为两个单词,否则PHP会因解析错误而失败.

Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.

这意味着在正常控制结构形式(即使用花括号)中:

Which means that in the normal control structure form (ie. using braces):

if (first_condition)
{

}
elseif (second_condition)
{

}

可以使用elseifelse if.但是,如果使用备用语法,则必须使用elseif:

either elseif or else if can be used. However, if you use the alternate syntax, you must use elseif:

if (first_condition):
  // ...
elseif (second_condition):
  // ...
endif;

这篇关于是"elseif"和"else if"完全同义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆