PHP supports arithmetic, comparison, logical, string concatenation, and assignment operators familiar from JavaScript—with a few PHP-specific surprises around type juggling.
Common operators
- Arithmetic:
+ - * / % ** - Concatenation:
.—'Hello, ' . $name - Comparison:
=== !== == != < > <= >= - Logical:
&& || !and word formsand or xor(lower precedence—avoid in new code) - Null coalescing:
??—$x ?? 'default' - Nullsafe (PHP 8+):
?->on objects
Increment and compound assignment
$n = 1;
$n += 2; // 3
$n++; // post-increment
Type juggling trap
var_dump(0 == 'foo'); // true (legacy quirk)
var_dump(0 === 'foo'); // false
Use strict comparison and explicit casting in production code.
Self-check
- Which operator concatenates strings?
- What does
$value ?? 'none'return when$valueis undefined?