PHP: operators
Operators combine values, calculate results, assign data, and compare conditions in PHP.
What you will learn
- How arithmetic and assignment operators change values
- How comparison operators produce true or false
- Why strict comparisons are safer when types matter
Common groups
- Arithmetic
+ - * / %calculate numbers.- Assignment
=stores a value;+=updates it.- Comparison
===checks value and type;!==checks that they differ.- Logical
&&,||, and!combine conditions.
<?php $age = 20; if ($age >= 18 && $age < 65) { echo 'Working-age example'; } ?>Use parentheses when they make the intended grouping clearer.
Common mistakes
- Prefer
===and!==when automatic type conversion would be surprising. - Do not use assignment
=where a comparison was intended. - Validate external input before converting it or using it in a condition.