PHP Arithmetic Operators

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

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 (Introduced in PHP 5.6)
<html>
    <head>
        <title>Three Plus Five</title>
    </head>
    <body>
        <h1>Three Plus Five</h1>
        <h3>Demonstrates use of numeric variables</h3>

        <?php
        $x = 3;
        $y = 5;

        print "$x + $y = ";
        print $x + $y;
        print "<br><br>";

        print "$x - $y = ";
        print $x - $y;
        print "<br><br>";

        print "$x * $y = ";
        print $x * $y;
        print "<br><br>";

        print "$x / $y = ";
        print $x / $y;
        print "<br><br>";

        $x = "Hello World";
        print $x;
        ?>
    </body>
</html>

No comments:

| Designed by Harhiktech