elseif

创建于 2024-12-03 / 27
字体: [默认] [大] [更大]

❮ PHP 关键字

实例

如果第一个条件不满足,则测试第二个条件:

<?php
if(5 < 3) {
  echo "Five is less than three";
} else if(5 > 4) {
  echo "Five is greater than four";
}
?> 亲自试一试 »

定义和用法

elseif 关键字测试一个新条件,如果之前的条件 ifelseif 语句。 这相当于将 if 语句放在 else 块中。

以下代码块是等价的:

<?php
if (...) {
some code here
} elseif (...) {
some code here
}
?> <?php
if (...) {
  some code here
} else{
  if (...) {
    some code here
  }
}
?>

相关页面

if关键字。

在我们的 PHP if else 教程中了解有关 if...elseif...else 条件的更多信息。


❮ PHP 关键字
0 人点赞过