Arithmetic Operators
| Operator | Description | Example | Result |
|---|---|---|---|
| + | Addition | x=4+3 | x=7 |
| - | Subtraction | x=10-3 | x=7 |
| * | Multiplication | x=2*9 | x=18 |
| / | Division | x=6/2 y=5/2 | x=3 y=2.5 |
| % | Modulus (division remainder) | x=7%2 y=9%3 z=10%4 | x=1 y=0 z=2 |
| ++ | Increment | x=8; x++; | x=9 |
| -- | Decrement | x=8; x--; | x=7 |
| Operator | Example | Equivalent |
|---|---|---|
| = | x=y | x=y |
| += | x+=y | x=x+y |
| -= | x-=y | x=x-y |
| *= | x*=y | x=x*y |
| /= | x/=y | x=x/y |
| .= | x.=y | x=x.y |
| %= | x%=y | x=x%y |
| Operator | Description | Example |
|---|---|---|
| == | is equal to | 2==2 returns true 3==2 returns false |
| != | is not equal | 2!=2 returns false 3!=2 returns true |
| <> | is not equal (only at PHP) | 2<>2 returns false 3<>2 returns true |
| > | is greater than | 2>3 returns false 3>2 returns true |
| < | is less than | 2<3 returns true 3<2 returns false |
| >= | is greater than or equal to | 2>=2 returns true 2>=3 returns false 3>=2 returns true |
| <= | is less than or equal to | 2<=2 returns true 2<=3 returns true 3<=2 returns false |
| Operator | Description | Example |
|---|---|---|
| && | and | x=2 y=3 (x < 5 && y > 2) returns true |
| || | or | x=2 y=3 (x < 1 && y > 2) returns true |
| ! | not | x=2 y=3 !(x==y) returns true |
No comments:
Post a Comment