Operator | Name | Example | Result
+ | Addition | $x + $y | Sum of $x and $y: 15
- | Subtraction | $x - $y | Difference of $x and $y: 5
* | Multiplication | $x * $y | Product of $x and $y: 50
/ | Division | $x / $y | Quotient of $x and $y: 2
% | Modulus | $x % $y | Remainder of $x divided by $y: 0
++ | Pre-increment | ++$a | Increments $a by one, then returns $a: 6
++ | Post-increment | $b++ | Returns $b, then increments $b by one: 5
You can conduct mathematical computations in PHP using arithmetic operators. Here are a few examples of common arithmetic operators:
Operator | Name | Example | Result |
---|---|---|---|
+ | Addition | $x + $y | Sum of $x and $y: 15 |
- | Subtraction | $x - $y | Difference of $x and $y: 5 |
* | Multiplication | $x * $y | Product of $x and $y: 50 |
/ | Division | $x / $y | Quotient of $x and $y: 2 |
% | Modulus | $x % $y | Remainder of $x divided by $y: 0 |
Additionally, there are increment operators:
Operator | Name | Example | Result |
---|---|---|---|
++ | Pre-increment | ++$a | Increments $a by one, then returns $a: 6 |
++ | Post-increment | $b++ | Returns $b, then increments $b by one: 5 |