PHP Operators
In PHP, operators are symbols or keywords used to perform operations on variables, values, or expressions. PHP provides a wide range of operators that can be categorized into several groups. Here are the main types of operators in PHP:
- Arithmetic Operators:
- Addition:
+
- Subtraction:
-
- Multiplication:
*
- Division:
/
- Modulo (remainder):
%
- Increment:
++
- Decrement:
--
- Addition:
- Assignment Operators:
- Assignment:
=
- Addition assignment:
+=
- Subtraction assignment:
-=
- Multiplication assignment:
*=
- Division assignment:
/=
- Modulo assignment:
%=
- Assignment:
- Comparison Operators:
- Equal to:
==
- Identical to:
===
- Not equal to:
!=
or<>
- Not identical to:
!==
- Greater than:
>
- Less than:
<
- Greater than or equal to:
>=
- Less than or equal to:
<=
- Equal to:
- Logical Operators:
- And:
&&
orand
- Or:
||
oror
- Not:
!
ornot
- Xor:
xor
- And:
- String Operators:
- Concatenation:
.
- Concatenation assignment:
.=
(e.g.,$str .= " World";
)
- Concatenation:
- Array Operators:
- Union:
+
- Equality:
==
- Identity:
===
- Inequality:
!=
or<>
- Non-identity:
!==
- Union:
- Conditional (Ternary) Operator:
- Ternary operator:
condition ? value_if_true : value_if_false
- Ternary operator:
- Type Operators:
- Instanceof:
instanceof
- Instanceof:
These are the basic operators in PHP, but there are more specialized operators available as well. It’s important to understand their usage and precedence rules to write effective PHP code.