Operators
PHP supports arithmetic operators (+, -, *, /, %), comparison operators (==, ===, !=, >, <), and logical operators (&&, ||, !). The === operator checks both value and type, while == only checks value this difference matters a lot in real code.
Why this matters
- ·=== avoids sneaky bugs from PHP's automatic type conversion
- ·% (modulus) is handy for checking even/odd numbers
Common mistakes
- ·Using == when you meant === can silently pass wrong comparisons
- ·Confusing = (assignment) with == (comparison) is a very common beginner bug
bool(true) bool(false)
PHP runs on a server, not in the browser this shows the expected output instead of a live one.
Frequently asked questions
Use the code editor above edit the example freely and check the expected output against your own reasoning.
Practice questions
Question 1
Write code that checks whether a number stored in $n is even, using the % operator.
PHP runs on a server, not in the browser this shows the expected output instead of a live one.
Quick check
Just for this topic answer honestly, then check yourself.
1 / 1
