downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

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&#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 <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">&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><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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites