What are the comparison operators in PHP basic syntax? Why are they compared? What are the different stories between them? This article will lead you to explore the charm of PHP, let’s go together
For comparison operators in mathematics, for example:
The operators in PHP are as shown in the figure:
##For example:x=3
y=5
x is wrong. For computers, right or wrong is judged based on the
bool (Boolean) data type, that is, true (
true) and false (
fals)
The code is as follows:
<?php $x = 3; $y = 5; //因为3大于5不成立,所以得出的结论是假的,即为false if($x > $y){ //结果为真 echo '变量x大于变量y,成立'; }else{ //结果为假 echo '变量x大于变量y,不成立'; } ?>
The result:
For equal to (= =) and all equal to
(= = =) they also belong to the judgment type, then the results between them are What's the difference?
<?php $x = 4; $y = '4'; if($x == $y){ echo '结果为真'; }else{ echo '结果为假'; } ?>
<?php $x = 4; $y = '4'; if($x === $y){ echo '结果为真'; }else{ echo '结果为假'; } ?>
Cause:
##$x = 4; //Shaping<br>
Therefore, the comparison found that
is also Called the judgment type equals. And $x is an integer type, $y is a character type, so the execution result is false, and for equals (= =)
does not judge the type, so the result is true Recommended learning: "
The above is the detailed content of Comparison operators of PHP basic syntax that even novices can learn. For more information, please follow other related articles on the PHP Chinese website!