除了"if"语句,php还提供了"if-else"结构,用来定义当语句中的条件描述为"false”值时所执行的php代码。
"if-else" 结构使用方法如下:
--------------------------------------------------------------------------------
if (condition)
{
do this!
}
else
{
do this!
}
--------------------------------------------------------------------------------
你将看到,这种结构可以用来对上一篇那个例子进行大大简化-替代两个分开的 "if" 语句嵌套,我们可以把他们混合在一个单一的"if-else" 语句中:
--------------------------------------------------------------------------------
< html>
< head>
< basefont face="arial">
< /head>
< body>
< center>
< ?
// 检查名字并反馈相应的信息
if ($name == "neo")
{
?>
< font face="arial" size="-1">
欢迎进入母体,neo。
< p>
也许是武力强迫你才这样做的,,,哦,不正当的影片!
< /font>
< ?
}
else
{
?>
< font face="arial" size="-1">
我想知道你是否听说过莎士比亚, < ? echo $name; ?>.
< p>
他要求得到一束另一个名字的玫瑰化,因为那束闻起来可能会更芳香一些。
< p>
对于你,很不幸,我不同意。拒绝进入!
< /font>
< ?
}
?>
< /center>
< /body>
< /html>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器