Arithmetic Operators
| Operator | Description | Example ( $x = 8; ) | Result |
|---|---|---|---|
| + | Addition | $x + 2; | 10 |
| - | Subtraction | $x - 2; | 6 |
| * | Multiplication | $x * 2; | 16 |
| / | Division | $x / 2; | 4 |
| % | Modulus (integer remainder after division) | $x % 2; $x % 5; |
2 3 |
| ++ | Increment | $x++; | $x = 9 |
| -- | Decrement | $x--; | $x = 7 |
Assignment Operators
| Operator | Example | Like Saying |
|---|---|---|
| = | $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; |
Comparison Operators
| Operator | Description | Example ( $x = 5; ) |
|---|---|---|
| == | is equal to | ( $x == 8 ) returns FALSE |
| != | is not equal | ( $x != 8 ) returns TRUE |
| > | is greater than | ( $x > 8 ) returns FALSE |
| < | is less than | ( $x < 8 ) returns TRUE |
| >= | is greater than or equal to | ( $x >= 8 ) returns FALSE |
| <= | is less than or equal to | ( $x <= 8 ) returns TRUE |
Logical Operators
| Operator | Description | Example ( $x = 7; $y = 4; ) |
|---|---|---|
| && | and | ( $x < 10 && $y > 1 ) returns TRUE |
| || | or | ( $x == 5 || $y == 5 ) returns FALSE |
| ! | not | !( $x == $y ) returns TRUE |
Concatenation Operators
| Operator | Description | Example ( $a = "Hello "; $b = "World"; ) |
|---|---|---|
| . | join | print( $a . $b ); // prints "Hello World" |
| .= | append | $a .= $b; // $a now equals "Hello World" |