在 PHP 中,是否允许以下逻辑
If (x && y)
//Do A
Elseif (x)
// Do B
Elseif (y)
// Do C
Else
// Do D
基本上,您可以使用多个 elseif 吗?
在 PHP 中,是否允许以下逻辑
If (x && y)
//Do A
Elseif (x)
// Do B
Elseif (y)
// Do C
Else
// Do D
基本上,您可以使用多个 elseif 吗?
是的:
if ($x && $y) {
//Do A
} else if ($x) {
// Do B
} else if ($y) {
// Do C
} else {
// Do D
}
另一种对 HTML 文件有用的格式
<?php if ($x && $y): ?>
Element A
<?php elseif ($x): ?>
Element B
<?php elseif ($y): ?>
Element C
<?php else: ?>
Element D
<?php endif;?>
对
if(this == this && this == this){
//this and that
}else if(this == that || this == that){
//this or that
}else{
//anything else
}
是的,尽管如果测试很简单($a == $b
),请改用开关:
switch ($a) {
case $b:
break;
case $c:
break;
default:
//Like else
}
您可以使用
if($x)
// for one line of code
elseif($y)
// also for one line of code
if($x) {
// for more than
// one line of code
} elseif($y) {
// also for multi-
// line codes
}
和
if($x):
// multi-line
endif;