The Math Operators


We'll start with the math operators, which are the most basic of all operators:

+

Adds two numbers

-

Subtracts one number from another

*

Multiplies two numbers together

/

Divides one number by another

%

Returns the remainder when one number is divided by another (modulus).


You can see them all at work in phpmath.php; here's the PHP:

Example 2-1. Using the Math operators, phpmath.php
 <HTML>     <BODY>         <H1>The math operators</H1>         <?php             echo "5 + 2 = ", 5 + 2, "<BR>";             echo "5 - 2 = ", 5 - 2, "<BR>";             echo "5 * 2 = ", 5 * 2, "<BR>";             echo "5 / 2 = ", 5 / 2, "<BR>";             echo "5 % 2 = ", 5 % 2, "<BR>";         ?>     </BODY> </HTML> 

The results, all as expected, appear in Figure 2-1.

Figure 2-1. The math operators.




    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net