Current course:

PHP math


Addition
$var1 = 120;
$var2 = 25;
$var3 = $var1 + $var2;
echo $var3;
This will echo 145.

Subtraction
$var1 = 120;
$var2 = 25;
$var3 = $var1 - $var2;
echo $var3;
This will echo 95.

Multiplication & Division work the same way.

You can also do more than one calculation in one line:
$var1 = 10;
$var2 = 5;
$var3 = $var1 + $var1 / $var2 - $var1 * $var2;
What do you think this will return?

The above example follows the order of precedence.
Brackets, Division, Multiplication, Addition, Subtraction

Although it will follow the order of precedence, it's often written with brackets anyway for ease of viewing:
$var3 = $var1 + ($var1 / $var2) - ($var1 * $var2);

But brackets can also be used to force your own precedence (since brackets are first in the order).
$var3 = ($var1 + $var1) / ($var2 - $var1) * $var2; The MOD operator (%) returns the remainder after a division.
$var1 = 25 % 3;
This would return 1. Three divides evenly into 24, which is one less than 25.
$var1 = 25 % 9;
This would return 7. Nine divides evenly into 18, which is 7 less than 25.

There are MANY other math operators in PHP.
w3schools.com PHP Math Functions