In this tutorial, you shall learn about Arithmetic Operators in PHP, different Arithmetic Operators available in PHP, their symbols, and how to use them in PHP programs, with examples.
Arithmetic Operators are used to perform basic mathematical arithmetic operators like addition, subtraction, multiplication, etc.
Arithmetic Operators Table
The following table lists out all the arithmetic operators in PHP programming.
|Addition||+||Returns addition of |
|Subtraction||–||Returns the subtraction of |
|Multiplication||*||Returns the multiplication of |
|Division||/||Returns the quotient of the result of division of |
|Modulus||%||Returns the reminder of division of |
In the following program, we will take values in variables
$y, and perform arithmetic operations on these values using PHP Arithmetic Operators.
<?php $x = 5; $y = 2; $addition = $x + $y; $subtraction = $x - $y; $multiplication = $x * $y; $division = $x / $y; $modulus = $x % $y; $exponentiation = $x ** $y; echo "x = $x" . "<br>"; echo "y = $y" . "<br>"; echo "x + y = $addition" . "<br>"; echo "x - y = $subtraction" . "<br>"; echo "x * y = $multiplication" . "<br>"; echo "x / y = $division" . "<br>"; echo "x % y = $modulus" . "<br>"; echo "x ** y = $exponentiation"; ?>
Arithmetic Operators Tutorials
The following tutorials cover each of the Arithmetic Operators in PHP, in detail with examples.
- PHP Addition PHP Tutorial on how to use Addition Operator to add two numbers.
- PHP Subtraction PHP Tutorial on how to use Subtraction Operator to subtract a number from another.
- PHP Multiplication PHP Tutorial on how to use Multiplication Operator to find the product of two numbers.
- PHP Division PHP Tutorial on how to use Division Operator to find the quotient of division of given two numbers.
- PHP Modulus PHP Tutorial on how to use Modulo Operator to find the remainder of integer division of given two numbers.
- PHP Exponentiation PHP Tutorial on how to use Increment Operator to increase the value in a variable by one.
In this PHP Tutorial, we learned about all the Arithmetic Operators in PHP programming, with examples.