The most common PHP operators are
- Assignment operators,
- Arithmetic operators,
- combined operators,
- comparison operators,
- logical operators.
- Relational Operators
- Increment and Decrement Operator
- Negation Operator
- Error Controlling operator
- String/Concatenation operator
- Conditional(or) Ternary Operator
- "new" Operator
- "instanceOf" operator
- Scope resolution operator
- Dereferencing operator
Assignment Operators
The basic assignment operator in PHP is "=". This means that the operand to the left of "=" gets set to the value to the right of "=".
Arithmetic Operators
| Operator | Example | Result |
| + | 4 + 2 | 6 |
| - | 4 - 2 | 2 |
| * | 4 * 2 | 8 |
| / | 4 / 2 | 2 |
| % | 4 % 2 | 0 |
| ++ | x = 4; x++; | x = 5 |
| -- | x = 4; x--; | x = 3 |
Combined Operators
You can combine an arithmetic operator with the assignment operator to form a combined operator. Combined operators are shown below:
| Operator | Example | Meaning |
| += | y += x | y = y + x |
| -= | y -= x | y = y - x |
| *= | y *= x | y = y * x |
| /= | y /= x | y = y / x |
| %= | y %= x | y = y % x |
Comparison Operators
| Operator | Meaning |
| == | is equal to |
| != | is not equal to |
| > | is greater than |
| >= | is greater than or equal to |
| < | is less than |
| <= | is less than or equal to |
Logical Operators
| Operator | Meaning |
| || | or |
| && | and |
| and | and |
| or | or |
| xor | xor |
| ! | not |
Relational Operators
= = = will check for the content and also for the type.
! = =
Increment and Decrement Operator
++ and - -
Negation Operator
- multiplying with (-1)
Error Controlling Operator:
@ when prepended an expression, any warning messages that is being generated will gets suppressed.
A PHP application is associated with two types of runtime mistakes:
- Warning - if warning occurs, the rest of the Programme will be executed.
- A Fatal error - if a fatal error occurs the Programme gets terminated.
String/concatenation operators:
. or .=
Conditional / ternery operator: ?:
No comments:
Post a Comment