The comparison operator is used for comparison. it is used to compare the results of two variables or expressions. if the comparison result is true, true is returned, otherwise, if the comparison result is false, false is returned. Through the previous series of PHP operators, we are now studying the sixth operator of the PHP operator"
Comparison Operators".
What are the comparison operators used?
The comparison operator is used for comparison. it is used to compare the results of two variables or expressions. if the comparison result is true, true is returned, otherwise, if the comparison result is false, false is returned.
Next, let's take a look at the comparison operators in PHP.
Comparison Operators
| Operator |
Name |
Example |
Description
|
| < |
Less |
$ X <$ y |
If $ x is less than $ y, true is returned. |
| > |
Greater |
$ X> $ y |
Returns true if $ x is greater than $ y. |
| <= |
Less than or equal |
$ X <= $ y |
If $ x is less than or equal to $ y, true is returned. |
| > = |
Greater than or equal |
$ X> = $ y |
If $ x is greater than or equal to $ y, true is returned. |
| = |
Equal |
$ X = $ y |
Returns true if $ x is equal to $ y. |
| ! = |
Not supported |
$ X! = $ Y |
Returns true if $ x is not equal to $ y. |
| === |
Heng et al. (quanet) |
$ X ===$ y |
Returns true if $ x is equal to $ y and has the same type. |
| ! = |
Non-constant (incomplete) |
$ X! ==$ Y |
Returns true if $ x is not equal to $ y and has different types. |
There are two comparison operators to be aware of, namely, "=" and "! = ". If you use the "=" operator for comparison, not only must the values be equal, but also the data type. for example, $ a = $ B, it means that $ a and $ B are not only equal in values, but also have the same data types as $ a and $ B .! = And = are the opposite, for example, $! = $ B indicates that $ a and $ B are not equal to the value or the data type.
Comparison operator instance
This example uses the comparison operator to compare the value of a variable. set the variable $ x = 100, the data type is integer, the variable $ y = "100", and the data type is string, compare $ x and $ y, and use "=", "=", "! = ","! = "Operator.
The code is as follows:
";var_dump($x === $y);echo "
";var_dump($x != $y);echo "
";var_dump($x !== $y);echo "
";?>
Code running result:
The others are relatively simple. I will not present them too much here. if you are interested, you can do it yourself. in the next section, we will explain the seventh "error control operator" of the PHP operator ".
Recommended articles:
1. PHP operator (1) "arithmetic operator" example
2. PHP operator (2) "string operator"
3. PHP operator (3) "value assignment operator" example
4. PHP operator (4) "bit operator" example
5. PHP operator (5) "logical operator" example
The above is the details of the PHP operator (6) "comparison operator" instance. For more information, see other related articles in the first PHP community!