📄 control-structures.else.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>else</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.if.html">if</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.elseif.html">elseif/else if</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="control-structures.else" class="sect1"> <h2 class="title"><i>else</i></h2> <p class="para"> Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what <i>else</i> is for. <i>else</i> extends an <i>if</i> statement to execute a statement in case the expression in the <i>if</i> statement evaluates to <b><tt>FALSE</tt></b>. For example, the following code would display <span class="computeroutput">a is bigger than b</span> if <var class="varname">$a</var> is bigger than <var class="varname">$b</var>, and <span class="computeroutput">a is NOT bigger than b</span> otherwise: <div class="informalexample"> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$a </span><span style="color: #007700">> </span><span style="color: #0000BB">$b</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"a is bigger than b"</span><span style="color: #007700">;<br />} else {<br /> echo </span><span style="color: #DD0000">"a is NOT bigger than b"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> The <i>else</i> statement is only executed if the <i>if</i> expression evaluated to <b><tt>FALSE</tt></b>, and if there were any <i>elseif</i> expressions - only if they evaluated to <b><tt>FALSE</tt></b> as well (see <a href="control-structures.elseif.html" class="link">elseif</a>). </p> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.if.html">if</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.elseif.html">elseif/else if</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -