本文介绍了是"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在技术上等效于如下嵌套结构:

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)
  {

  }
}

该手册还指出:

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

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"完全同义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 06:13