PHP Arithmetic Operators - PHP Operators - php developer

PHP Arithmetic Operators


Arithmetic operators in PHP

PHP supports all standard arithmetic operations, as illustrated by the list of Operators .

Common Arithmetic Operators
Operatos Description
+ Add
* Multiply
/ Divide and return quotient
% Divide and return modulus

Here’s example illustrating these operators in action

PHP Arithmetic operators are used to perform mathematical operation on more than one operands.

Some of the standard arithmetic operators are +,-,*,/,%.

The use of some common arithmetic operators is here illustrated by an example as follows:-

Arithmetic operators (+) for addition

sum = 15

Arithmetic operators (-) for subtraction

sub = 5

Arithmetic operators (*) for multiplication

Multiplication = 50

Arithmetic operators (/) for quotient

Div = 2

Arithmetic operators (%) for remainder

sub = 0

$x and $y are two integer variables here
there are five blocks/modules in this example they are to preform addition, subtraction, multiplication, division and modulus respectively.
$x store the value 10,
$y store the value 5.

The output of first module is addition of two values 10 and 5 that is 15 ($x+$y=15).
The output of second module is subtraction of two values 10 and 5 that is 5 ($x-$y=5).
The output of third module is multiplication of two values 10 and 5 that is 50 ($x*$y=50).
The output of fourth module is division of two values 10 and 5 that is 2 ($x/$y=2).
The output of last module is modulus of two values 10 and 3 that is 1 ($x%$y=1).