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

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.

OperatorSymbolExampleDescription
Addition+ x + y Returns addition of x and y.
Subtraction x - y Returns the subtraction of y from x.
Multiplication* x * y Returns the multiplication of x and y.
Division/ x / y Returns the quotient of the result of division of x by y.
Modulus% x % y Returns the reminder of division of x by y. Known as modular division.
Exponent** x ** y Returns x raised to the power y.

Example

In the following program, we will take values in variables $x and $y, and perform arithmetic operations on these values using PHP Arithmetic Operators.

PHP Program

</>
Copy
<?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";
?>

Output