The inequality operators in php are "!=", "!==" and "<>". The "!=" and "<>" operators are completely equivalent, without any difference, and are used to compare whether the values of two objects are equal; while the "!==" operator indicates absolute inequality. In addition to comparing values, it also Will compare types.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php inequality operator
Operator | Name | Description | Instance |
---|---|---|---|
x != y | is not equal to | If x is not equal to y, return true | 5!=8 Return true |
x <> y | is not equal to | If x is not equal to y, return true | 5<>8 Return true |
x !== y | Absolutely not equal | If x is not equal to y, or they are not the same type, return true | 5!= ="5" returns true |
Instructions: In
php, <>
and !=
These two are completely equivalent, without any difference. They are used to compare whether the values of two objects are equal.
is not equal to !==
In addition to comparing values, types will also be compared.
For example: 1 != '1'
will return false, because the values of number 1 and string 1 are equal,
1 !== '1'
will return true because the two types are not equal
Example:
<?php $x=100; $y="100"; var_dump($x == $y); // returns true because values are equal echo "<br>"; var_dump($x === $y); // returns false because types are not equal echo "<br>"; var_dump($x != $y); // returns false because values are equal echo "<br>"; var_dump($x !== $y); // returns true because types are not equal echo "<br>"; $a=50; $b=90; var_dump($a > $b); echo "<br>"; var_dump($a < $b); ?>
Output:
bool(true) bool(false) bool(false) bool(true) bool(false) bool(true)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the inequality operator in php and what. For more information, please follow other related articles on the PHP Chinese website!