PHP basic syntax comparison operators
Comparison operators, we learned a lot when we were in elementary school, they are:
Explanation | symbols |
---|---|
is greater than | > |
is less than | < |
Greater than or equal to | ≥ |
≤ | |
≠ | |
= |
Symbol | |
---|---|
> | |
< | |
>= | |
<= | |
!= | |
== (the assignment is = sign, so == is specified as equal) | |
=== | |
!== |
y = 6
x
We learned judgment questions similar to this when we were in elementary school.The right and wrong in the computer are the true and false of the bool (Boolean) data type.
Then, can we use the if...else we learned before to determine the type?
$y){ //真区间 echo '变量x 大于 变量y,成立'; }else{ //假区间 echo '变量x 大于 变量y,不成立'; } ?>I think, if you graduate from elementary school. Less than, less than or equal to, size equal to, and not equal to will all be tested. Please experiment a few times. Moreover, it is completely possible to write silently! The next key point is the demonstration, equal (==) and equal to all are also called judgment type equal (===). Let's write a piece of code. Let's take a look at the two pieces of code. They are symbols of PHP Academy. Why is there such a big gap in the results?
The result of executing the following code is the true interval.
The result of executing the following code is a false interval.
The following code is === (three equal signs, we say it also has a name for judging type equals). And $x is an integer type 5. $y is a string type 5. Type PHP Academy, so a false interval is executed. In the above piece of code, the two equal signs do not determine the type, so the true interval is executed.