PHP operators are symbols that perform specific operations on one or more operands (values). These operators can be grouped into the following categories:
- Arithmetic operators: These include the basic arithmetic operators such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
- Comparison operators: These operators are used to compare two values and return a boolean result (true or false). Examples include equals (==), not equals (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=).
- Logical operators: These operators perform logical operations such as AND (&&), OR (||), and NOT (!). They are used to combine two or more conditions in a statement.
- Assignment operators: These operators are used to assign a value to a variable. Examples include the simple assignment operator (=), as well as compound assignment operators such as +=, -=, *=, and /=.
- Increment and decrement operators: These operators are used to increase or decrease the value of a variable by 1. The increment operator (++) adds 1, while the decrement operator (–) subtracts 1.
- String operators: These operators are used to concatenate (join) two or more strings together. The concatenation operator is the period (.) character.
- Array operators: These operators are used to compare arrays or to perform operations on arrays. Examples include the union operator (+), the intersection operator (.), and the difference operator (-).
In addition to these operators, PHP also supports a range of other operators such as the ternary operator (?:), the null coalescing operator (??), and the spaceship operator (<=>). These operators can be used to perform more advanced operations and to make code more concise and readable.