Operators
Operators help you not only to perform mathematical or logical operations but they are also a good way to compare values or redirect values.
Arithmetic operators
Arithmetic operators can be used to calculate values. They are as follows:
- Addition (+):
> $a = 3; $b = 5; $result = $a + $b
> $result
8
- Subtraction (-):
> $a = 3; $b = 5; $result = $b - $a
> $result
2
- Multiplication (*):
> $a = 3; $b = 5; $result = $a * $b
> $result
15
- Division (/):
> $a = 12; $b = 4; $result = $a / $b
> $result
3
- Modulus (%): In case you have never worked with modulus in the past, % is a great way to check whether there is a remainder if a number is divided by a divisor. Modulus provides you with the remainder:
> 7%2
1
> 8%2
0
> 7%4
3
Of course, you can also combine different arithmetic operators as you are used to:
> $a = 3; $b = 5; $c = 2
> $result = ($a + $b) * $c
> $result
16
When combining different arithmetic operators...