Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 1234

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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&#039;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">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"a&nbsp;is&nbsp;greater&nbsp;than&nbsp;b"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"a&nbsp;is&nbsp;NOT&nbsp;greater&nbsp;than&nbsp;b"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</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>