<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>else</title> </head> <body><div class="manualnavbar" 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"><em>else</em></h2> <p class="verinfo">(PHP 4, PHP 5)</p> <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 <em>else</em> is for. <em>else</em> extends an <em>if</em> statement to execute a statement in case the expression in the <em>if</em> statement evaluates to <strong><code>FALSE</code></strong>. For example, the following code would display <span class="computeroutput">a is greater than b</span> if <var class="varname"><var class="varname">$a</var></var> is greater than <var class="varname"><var class="varname">$b</var></var>, and <span class="computeroutput">a is NOT greater 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 greater than b"</span><span style="color: #007700">;<br />} else {<br /> echo </span><span style="color: #DD0000">"a is NOT greater than b"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> The <em>else</em> statement is only executed if the <em>if</em> expression evaluated to <strong><code>FALSE</code></strong>, and if there were any <em>elseif</em> expressions - only if they evaluated to <strong><code>FALSE</code></strong> as well (see <a href="control-structures.elseif.html" class="link">elseif</a>). </p> </div><hr /><div class="manualnavbar" 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>