Table of Contents

    PHP Arithmetic Operators: Basic Math Operations in PHP

    PHP Arithmetic Operators: Basic Math Operations in PHP

    PHP Arithmetic Operators

    The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

    Operator Name Example Result
    + Addition $x + $y Sum of $x and $y
    - Subtraction $x - $y Difference of $x and $y
    * Multiplication $x * $y Product of $x and $y
    / Division $x / $y Quotient of $x and $y
    % Modulus $x % $y Remainder of $x divided by $y
    ** Exponentiation $x ** $y Result of raising $x to the $y'th power

    Addition

    Syntax:

    
    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $x = 10;  
    $y = 6;
    
    echo $x + $y;
    ?>  
    
    </body>
    </html>
    
    
    

    Output:

    
    16
    
    

    Subtraction

    Syntax:

    
    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $x = 10;  
    $y = 6;
    
    echo $x - $y;
    ?>  
    
    </body>
    </html>
    
    
    

    Output:

    
    
    4
    

    Multiplication

    Syntax:

    
    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $x = 10;  
    $y = 6;
    
    echo $x * $y;
    ?>  
    
    </body>
    </html>
    
    
    

    Output:

    
    60
    
    

    Division

    Syntax:

    
    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $x = 10;  
    $y = 6;
    
    echo $x / $y;
    ?>  
    
    </body>
    </html>
    
    

    Output:

    
    1.6666666666667
    
    

    Modulus

    Syntax:

    
    
    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $x = 10;  
    $y = 6;
    
    echo $x % $y;
    ?>  
    
    </body>
    </html>
    
    

    Output:

    
    
    4
    

    Exponentiation

    Syntax:

    
    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $x = 10;  
    $y = 3;
    
    echo $x ** $y;
    ?>  
    
    </body>
    </html>
    
    
    

    Output:

    
    1000