print "a is bigger than b";DMP站长资讯
通常,你希望根据条件执行多于一条语句。当然,不需要给每条语句都加上 IF 判断。取而代之,可以把多条语句组成一个语句组。
If语句可以嵌套于其他 IF语句中,使你能够灵活地有条件的执行程序的各个部分。
2、 ELSE语句
通常你希望满足特定条件时执行一条语句,不满足条件是执行另一条语句。ELSE就是用来做这个的。ELSE 扩展IF语句,在IF语句表达式为FALSE时执行另一条语句。例如, 下面程序执行如果 $a 大于 $b则显示 'a is bigger than b',否则显示 'a is NOT bigger than b':
if ($a>$b) {
print "a is bigger than b";
}
else {
print "a is NOT bigger than b";
}
3、 ELSEIF语句
ELSEIF,就象名字所示,是IF和ELSE的组合,类似于 ELSE,它扩展 IF 语句在IF表达式为 FALSE时执行其他的语句。但与ELSE不同,它只在ELSEIF表达式也为TRUE时执行其他语句。
/* example 1 */
$i=1;
while ($i<=10) {
print $i++; /* the printed value would be $i before the increment (post-
increment) */
}
/* example 2 */
$i=1;
while ($i<=10):
print $i;
$i++;
endwhile;