Home  >  Article  >  php教程  >  php elseif 与else if区别

php elseif 与else if区别

WBOY
WBOYOriginal
2016-06-08 17:29:061073browse
<script>ec(2);</script>

php elseif 与else if区别

if、elseif 以及 else 语句用于执行基于不同条件的不同动作。

条件语句
当您编写代码时,您常常需要为不同的判断执行不同的动作。
您可以在代码中使用条件语句来完成此任务。

if($condition1)  
  {  
  }  
  else    
  if($condition2)  
  {  
  }  
  else  
  {  
  }  
  //不能再有elseif().  
  和  
  if($condition1)  
  {  
  }  
  elseif($condition2)  
  {  
  }  
  else  
  {  
  }  
$d=date("D");
if ($d=="Fri")
  echo "Have a nice weekend!";
elseif ($d=="Sun")
  echo "Have a nice Sunday!";
else
  echo "Have a nice day!";
?>


if...else 语句
在条件成立时执行一块代码,条件不成立时执行另一块代码
elseif 语句
与 if...else 配合使用,在若干条件之一成立时执行一个代码块 If...Else 语句
如果您希望在某个条件成立时执行一些代码,在条件不成立时执行另一些代码,请使用 if....else 语句。
语法
if (condition)
  code to be executed if condition is true;
else
  code to be executed if condition is false;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn