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/language.operators.arithmetic.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/language.operators.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'language.operators.arithmetic.php',
   
1 => 'Arithmetic Operators',
  ),
 
'up' =>
  array (
   
0 => 'language.operators.php',
   
1 => 'Operators',
  ),
 
'prev' =>
  array (
   
0 => 'language.operators.precedence.php',
   
1 => 'Operator Precedence',
  ),
 
'next' =>
  array (
   
0 => 'language.operators.assignment.php',
   
1 => 'Assignment Operators',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="language.operators.arithmetic" class="sect1">
   <h2 class="title">Arithmetic Operators</h2>
   <p class="simpara">
    Remember basic arithmetic from school? These work just
    like those.
   </p>
   <table class="doctable table">
    <caption><b>Arithmetic Operators</b></caption>
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Example</th>
       <th>Name</th>
       <th>Result</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">-$a</td>
       <td align="left">Negation</td>
       <td align="left">Opposite of <var class="varname">$a</var>.</td>
      </tr>

      <tr valign="middle">
       <td align="left">$a + $b</td>
       <td align="left">Addition</td>
       <td align="left">Sum of <var class="varname">$a</var> and <var class="varname">$b</var>.</td>
      </tr>

      <tr valign="middle">
       <td align="left">$a - $b</td>
       <td align="left">Subtraction</td>
       <td align="left">Difference of <var class="varname">$a</var> and <var class="varname">$b</var>.</td>
      </tr>

      <tr valign="middle">
       <td align="left">$a * $b</td>
       <td align="left">Multiplication</td>
       <td align="left">Product of <var class="varname">$a</var> and <var class="varname">$b</var>.</td>
      </tr>

      <tr valign="middle">
       <td align="left">$a / $b</td>
       <td align="left">Division</td>
       <td align="left">Quotient of <var class="varname">$a</var> and <var class="varname">$b</var>.</td>
      </tr>

      <tr valign="middle">
       <td align="left">$a % $b</td>
       <td align="left">Modulus</td>
       <td align="left">Remainder of <var class="varname">$a</var> divided by <var class="varname">$b</var>.</td>
      </tr>

     </tbody>
   
   </table>

   <p class="simpara">
    The division operator (&quot;/&quot;) returns a float value unless the two operands
    are integers (or strings that get converted to integers) and the numbers
    are evenly divisible, in which case an integer value will be returned.
   </p>
   <p class="simpara">
    Operands of modulus are converted to integers (by stripping the decimal
    part) before processing.
   </p>
   <blockquote><p><b class="note">Note</b>:
    <span class="simpara">
     Remainder <i>$a % $b</i> is negative for negative
     <i>$a</i>.
    </span>
   </p></blockquote>
   <p class="simpara">
    See also the manual page on
    <a href="ref.math.php" class="link">Math functions</a>.
   </p>

  </div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites