This section contains the detail about Arithmetic Operators in PHP.
This section contains the detail about Arithmetic Operators in PHP.Operator is used to perform operation on variable and values. Arithmetic Operators is used to perform arithmetic operations(like addition, subtraction, multiply divide etc )on variables and numeric.
Given below the list of available arithmetic operators :
OPERATOR | WORK | USE | RESULT |
+ | Addition | y=3 y+3 |
6 |
- | Subtraction | y=3 5-y |
2 |
/ | Division | 21/3 |
7 |
% | Modulus (division remainder) | 10%8 |
2 |
++ | Increment | y=3 y++ |
4 |
* | Multiplication | y=3 y*3 |
9 |
-- | Decrement | y=5 y-- |
4 |
Some of the key notes are given below, which you should keep in mind before applying these arithmetic operator :
<?php echo (5 % 3)."\n"; // output 2 echo (5 % -3)."\n"; // output 2 echo (-5 % 3)."\n"; // output -2 echo (-5 % -3)."\n"; // output -2 ?>