Learning from the preceding series of PHP operators, today we learn the sixth operator of the PHP operator "
comparison Operators”。
What is the comparison operator used for?
Comparison operators you literally understand that it is used to compare, it is the result of two variables or expressions of the size, true and false comparison, if the results are true, return true, conversely, if the result of the comparison is false, then return FALSE.
Let's take a look at what the comparison operators in PHP have
Comparison operators
| Operator |
Name |
Example |
Description
|
| < |
Less than |
$x < $y |
Returns True if the $x is less than $y. |
| > |
Greater than |
$x > $y |
Returns True if the $x is greater than $y |
| <= |
Less than or equal |
$x <= $y |
Returns True if $x is less than or equal to $y. |
| >= |
Greater than or equal |
$x >= $y |
Returns true if $x is greater than or equal to $y. |
| == |
Equal |
$x = = $y |
Returns True if the $x equals $y. |
| != |
Range |
$x! = $y |
Returns true if $x is not equal to $y |
| === |
Identity (congruent) |
$x = = = $y |
Returns True if $x equals $y and they are of the same type |
| !== |
Non-identical (not congruent) |
$x!== $y |
Returns true if $x are not equal to $y and they are of different types |
There are two comparison operators that need attention, which is "= = =" and "! = = ". Using the "= = =" Operator For comparison, not only is the value equal, but also on the data type, for example, $a = = = $b, stating that $ A and $b are not only exactly equal in value, but also the same as the data type of $ A and $b. = = = = = = = = = = = opposite, e.g. $a! = = $b, which means $ A and $b or different numbers or data types.
Comparison operator Instances
This example uses comparison operators to compare the values of variables, set the variable $x=100, the data type is integer, the variable $y= "100", the data type is a string, compares $x and $y, uses "= =", "= = =", "! = ","! = = = operator.
The code is as follows
<?php$x=100; $y = "Var_dump"; ($x = = $y); echo "<br>"; var_dump ($x = = = $y); echo "<br>"; Var_dump ($x! = $y); echo "<br>"; Var_dump ($x!== $y); echo "<br>";? >
Code Run Result:
The other several relatively simple, here do not do too much demonstration, interested can do it yourself, the next section, we will explain the PHP operator seventh "error control operator."
Related articles recommended:
1.PHP operator (i) An example of "arithmetic operator" explained
2.PHP operator (ii) a detailed example of a "string operator"
3.PHP operator (c) "Assignment operator" Example explained
4.PHP operator (iv) "Bitwise operator" Walkthrough
5.PHP operator (v) "logical operator" Instance explained