Operator supported by PHP:
- Arithmetic operators.
- Assignment operators.
- Comparison operators.
- Increment/Decrement operators.
- Logical operators.
- String operators.
- Array operators.
Arithmetic Operator:
Operator | Meaning | Operator | Meaning |
-$a | Negation | $a/$b | Division |
$a+$b | Addition | $a%$b | Modulus |
$a-$b | Subtraction | $a**$b | Exponentiation |
$a*$b | Multiplication |
- “-” Is used for both negation and subtraction. + for addition. * for multiplication and / for a division.
- “%” is used for modulus operator used to find the remainder in division.
- ** is exponentiation operator. Value on the left to the power value in right.
Example:
1 2 3 4 5 6 7 8 9 |
$a = 10; $b = 5; echo -$a. '<br>'; echo $a + $b.'<br>'; echo $a - $b.'<br>'; echo $a * $b.'<br>'; echo $a / $b.'<br>'; echo $a % $b.'<br>'; |
Logical Operators:
Operator | Example | Meaning |
&& | $a && $b | True if both $a and $b are true |
|| | $a || $b | True if either $a or $b is true |
! | !$a | Reverse meaning of $a |