PHP basic synta...LOGIN

PHP basic syntax comparison operators

Comparison operators, we learned a lot when we were in elementary school, they are:

## Less than or equal to ≤is not equal to ≠is equal to=
Explanation symbols
is greater than >
is less than <
Greater than or equal to
But in our case There is an additional operator in PHP:

DescriptionSymbolGreater than>##Less thanGreater than or equal to is less than or equal to is not equal to is equal to Congruent (judgment type is equal)Congruent (judgment type is not equal) Let’s review the knowledge we learned in elementary school:
<
>=
<=
!=
== (the assignment is = sign, so == is specified as equal)
===
!==

x = 5

y = 6

x<y is correct, because x is 5 and y is 6, so the judgment that x is less than y is correct

##x> y is wrong, because x is 5 and y is 6, so the judgment that x is greater than y is wrong

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?

<?php
$x = 5;

$y = 6;
//因为5大于6不成立,所以为错的。即为false执行了假区间
if($x > $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.

<?php
$x = 5;
$y = '5';
if($x == $y){
   echo '结果为真';
}else{
   echo '结果为假';
}
?>

The result of executing the following code is a false interval.

<?php
$x = 5;
$y = '5';
if($x === $y){
   echo '结果为真';
}else{
   echo '结果为假';
}

?>

We compared the differences and found:

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.

Next Section
<?php $x = 5; $y = '5'; if($x === $y){ echo '结果为真'; }else{ echo '结果为假'; } ?>
submitReset Code
ChapterCourseware