1. Arithmetic Operators
Used to perform mathematical computations:
2. Assignment Operators
Used to write and update variable values:
3. Comparison Operators
Used in conditional statements to test equality and relational order:
| Operator | Name | Description | Example |
|---|---|---|---|
== |
Equal | True if values are equal after type coercion. | 5 == "5" // true |
=== |
Identical | True only if values AND data types are equal. | 5 === "5" // false |
!= or <> |
Not equal | True if values are not equal. | 10 != 20 // true |
!== |
Not identical | True if value or type does not match. | 5 !== "5" // true |
<=> |
Spaceship | Returns -1 (less), 0 (equal), or 1 (greater). | 5 <=> 10 // -1 |
4. Logical Operators
&&(AND): True if both operands are true.||(OR): True if at least one operand is true.!(NOT): Inverts boolean truth value.
5. Ternary and Null Coalescing Operator (??)
= 18) ? "Eligible to vote" : "Minor";
// Null Coalescing Operator: returns first operand if set and not null
$username = $_GET['user'] ?? "Guest User";
echo "Welcome, " . $username;