Arithmetic Operators : PHP



PHP Arithmetical Operators :

Suppose value of A is 20 and B is 5 then consider –

Operator Description Example
+ Addition of two operands A + B will give 25
- Subtraction of second operand from the first A – B will give 15
* Multiply both operands A * B will give 100
/ Divide numerator by denominator A / B will give 4
% Modulus Operator and remainder of after an integer division A % B will give 0
++ Increment operator increases integer value by one A++ will give 21
#8211; Decrement operator decreases integer value by one A#8211; will give 19

Example : Artihmetic Operators

<html>
<head><title>Arithmetical Operators</title><head>
<body>
<?php
    $num1 = 100;
    $num2 = 20;
    
    $result = $num1 + $num2;
    echo "Addtion Result: $result <br/>";
	
    $result = $num1 - $num2;
    echo "Substraction Result: $result <br/>";

    $result = $num1 * $num2;
    echo "Multiplication Result: $result <br/>";

    $result = $num1 / $num2;
    echo "Division Result: $result <br/>";

    $result = $num1 % $num2;
    echo "Modulus Result: $result <br/>";

    $result = $num1++; 
    echo "Increment Result: $result <br/>";

    $result = $num1--; 
    echo "Decrement Result: $result <br/>";
?>
</body>
</html>

Output :

Addtion Result: 120 
Substraction Result: 80 
Multiplication Result: 2000 
Division Result: 5 
Modulus Result: 0 
Increment Result: 100 
Decrement Result: 101