Source of: /manual/en/control-structures.else.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.control-structures.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'control-structures.else.php',
1 => 'else',
),
'up' =>
array (
0 => 'language.control-structures.php',
1 => 'Control Structures',
),
'prev' =>
array (
0 => 'control-structures.if.php',
1 => 'if',
),
'next' =>
array (
0 => 'control-structures.elseif.php',
1 => 'elseif/else if',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<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 class="constant">FALSE</tt></b>. For example, the following
code would display <span class="computeroutput">a is greater than
b</span> if <var class="varname">$a</var> is greater than
<var class="varname">$b</var>, and <span class="computeroutput">a is NOT greater
than b</span> otherwise:
</p><div class="informalexample">
<div class="example-contents programlisting">
<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><p>
The <i>else</i> statement is only executed if the
<i>if</i> expression evaluated to
<b><tt class="constant">FALSE</tt></b>, and if there were any
<i>elseif</i> expressions - only if they evaluated to
<b><tt class="constant">FALSE</tt></b> as well (see <a href="control-structures.elseif.php" class="link">elseif</a>).
</p>
</div><?php manual_footer(); ?>