php arithmetic
php arithmetic
numeric values. The following table highligts the arithmetic operators that
are supported by PHP. Assume variable "$a" holds 42 and variable "$b" holds
20 −
Operator Description
1.1 Example
The following example shows how you can use these arithmetic operators in
PHP −
Open Compiler
<?php
$a = 42;
$b = 20;
$c = $a + $b;
echo "Addtion Operation Result: $c \n";
$c = $a - $b;
echo "Substraction Operation Result: $c \n";
$c = $a * $b;
echo "Multiplication Operation Result: $c \n";
$c = $a / $b;
echo "Division Operation Result: $c \n";
$c = $a % $b;
echo "Modulus Operation Result: $c \n";
$c = $a++;
echo "Increment Operation Result: $c \n";
$c = $a--;
echo "Decrement Operation Result: $c";
?>
It will produce the following output −
Addtion Operation Result: 62
Substraction Operation Result: 22
Multiplication Operation Result: 840
Division Operation Result: 2.1
Modulus Operation Result: 2
Increment Operation Result: 42
Decrement Operation Result: 43