PHP Arithmetic Operators

The arithmetic operators are operators we see commonly in everyday use. Apart from arithmetic negation and arithmetic assertion operators, most Arithmetic operators are binary.

PHP provides plenty of mathematical functions for basic calculations and conversions, calculating logarithms, square roots, geometric values, etc.

Numeric operators take integer or floating-point arguments and compute a result on them. Both left and right arguments to an operator have the same numeric type (integer or floating-point). Still, it is possible to mix these, putting an integer on the left side and floating-point on the right side or the other way around. These operators require numeric values, and non-numeric values are converted into numeric values.

Arithmetic operators combine operands consisting of one or more variables and constants. Arithmetic operators supported by PHP are addition(+),subtraction(-),multiplication(*),division(/) and modulus(%).

OperatorNameExampleDescription
+Addition$m * $n Return the sum of both operands $m and $n
Substration$m – $n Return the difference of both operands $m and $n
*Multiplication$m * $n Return the product of both operands $m and $n
/Division$m / $n Return the quotient of both operands $m and $n
%Modulo$m % $n Return the remainder of both operands $m divided by $n
**Exponentiation$m ** $n Return the result of both operands raising $mto the $n'th power.

PHP - Addition Operator(+)

Both operands are added and returned as output.

			

<?php
$a = 10;  
$b = 10;
echo $a + $b;
?>  

				

Output:

20

PHP - Subtraction Operator(-)

Subtracts both operands and returns as output.

			

<?php
$a = 20;  
$b = 10;

echo $a - $b;
?>  

				

Output:

10

PHP - Multiplication Operator(*)

Multiplies both operands and returns as output.

			

<?php
$a = 10;  
$b = 10;

echo $a * $b;
?> 

				

Output:

100

PHP - Division Operator(/)

Divides numerator by denominator and returns as output.

			

<?php
$a = 20;  
$b = 10;

echo $a / $b;
?>  

				

Output:

2

PHP - Modulus Operator(%)

Returns the remainder after the division of the operands.

			

<?php
$a = 20;  
$b = 10;

echo $a % $b;
?>

				

Output:

0