超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<流程控制elseif>
Last updated: Fri, 22 Jun 2007

else

经常需要在满足某个条件时执行一条语句,而在不满足该条件时执行其它语句,这正是 else 的功能。else 延伸了 if 语句,可以在 if 语句中的表达式的值为 FALSE 时执行语句。例如以下代码在 $a 大于 $b 时显示 a is bigger than b,反之则显示 a is NOT bigger than b

<?php
if ($a > $b) {
   print
"a is bigger than b";
} else {
   print
"a is NOT bigger than b";
}
?>

else 语句仅在 if 以及 elseif(如果有的话)语句中的表达式的值为 FALSE 时执行(参见 elseif)。




add a note add a note User Contributed Notes
else
cap at capsi dot com
06-Oct-2000 01:58
Often you can avoid large if/else statements in your code by using the ternary operator. For example:

<?php
echo "You have $i ". ($i==1 ? "message" : "messages"). " in your mailbox.\n";
?>

<流程控制elseif>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22