This section contains detail about Operators in PHP.
Operators in PHP
Operator is used to perform operation on variable and values. PHP operators can be classified into the following categories :
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
Arithmetic Operators
OPERATOR | WORK | USE | RESULT |
+ | Addition | y=3 y+3 |
6 |
- | Subtraction | y=3 5-y |
2 |
/ | Division | 21/3 |
7 |
% | Modulus (division remainder) | 10%8 |
2 |
++ | Increment | y=3 y++ |
4 |
* | Multiplication | y=3 y*3 |
9 |
-- | Decrement | y=5 y-- |
4 |
Assignment Operators
OPERATOR | USE | EQUIVALENT TO |
= | a=b | a=b |
+= | a+=b | a=a+b |
-= | a-=b | a=a-b |
*= | a*=b | a=a*b |
/= | a/=b | a=a/b |
.= | a.=b | a=a.b |
%= | a%=b | a=a%b |
Comparison Operators
OPERATOR | NAME | EXAMPLE |
= = | is equal to | 5= =8 returns false |
!= | is not equal | 5!=8 returns true |
<> | is not equal | 5<>8 returns true |
> | is greater than | 5>8 returns false |
< | is less than | 5<8 returns true |
>= | is greater than or equal to | 5>=8 returns false |
<= | is less than or equal to | 5<=8 returns true |
Logical Operators
OPERATOR | NAME | EXAMPLE |
&& | And | a=7 b=6 (a< 12 && b> 3) returns true |
|| | Or | a=3 b=9 (x==4 || y==4) returns false |
! | Not | x=3 y=4 !(x==y) returns true |
[ 0 ] Comments