Comparison¶
Comparison operators check how two values relate to each other. They may be equal or different, and, depending on the type of compared data, they may be greater or lesser than the other one.
PHP comparisons exists with type-juggling, ==, <>, <=>, switch() and !=, and with type checks, match(), === and !==. They are called loose comparison, as PHP applies some cast before executing the comparison. Inequalities only exist with type-juggling.
On the other hand, PHP has strict comparisons, which include comparing the type before running any further checks. They are === and !==.
There are also functions dedicated to comparisons, with specific applications: strcmp(), strcasecmp(), strnatcasecmp(), strcoll(), similar_text(), levensthein(), bccomp(), version_compare(), hash_equals().
Some of the functions include a loose or a strict version.
<?php
if ($a == $b) {
print 'a and b are equal';
}
?>
See also PHP Variable Comparison and Difference between the (=), (==), and (===) operators in PHP.
Related : Operators, Type Juggling, Switch, Match, Spaceship Operator, Magic Hash, Truthy, Underscore, zero, Identity Comparison, Relaxed Comparison, array_keys(), Double Arrow, Triple