Home  >  Article  >  Backend Development  >  Comparison operators of PHP basic syntax that even novices can learn

Comparison operators of PHP basic syntax that even novices can learn

慕斯
慕斯Original
2021-05-20 17:47:021684browse

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

Comparison operators of PHP basic syntax that even novices can learn

For comparison operators in mathematics, for example:

Comparison operators of PHP basic syntax that even novices can learnThe operators in PHP are as shown in the figure:

Comparison operators of PHP basic syntax that even novices can learn

##For example:

x=3

y=5

x is correct, x>y is wrong. For computers, right or wrong is judged based on the bool (Boolean) data type, that is, true (true) and false (fals

So, to sum up, can we also use if...else to determine the type?

The answer is undoubtedly yes

The code is as follows:

<?php
$x = 3;
$y = 5;
//因为3大于5不成立,所以得出的结论是假的,即为false
if($x > $y){
    //结果为真
    echo &#39;变量x大于变量y,成立&#39;;
}else{
    //结果为假
    echo &#39;变量x大于变量y,不成立&#39;;
}
?>

The result:

Comparison operators of PHP basic syntax that even novices can learn

For equal to (= =) and all equal to (= = =) they also belong to the judgment type, then the results between them are What's the difference?

The equal code is as follows:

<?php
$x = 4;
$y = &#39;4&#39;;
if($x == $y){
    echo &#39;结果为真&#39;;
}else{
     echo &#39;结果为假&#39;;
}
?>

The result is as follows:

Comparison operators of PHP basic syntax that even novices can learn

The equal code is as follows:

<?php
$x = 4;
$y = &#39;4&#39;;
if($x === $y){
    echo &#39;结果为真&#39;;
}else{
     echo &#39;结果为假&#39;;
}
?>

The results are as follows:

Comparison operators of PHP basic syntax that even novices can learn

Cause:

##$x = 4; //Shaping

<br>

$y = '4';//String

Therefore, the comparison found that

is all equal to (= = =)

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: "

PHP video tutorial

"

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn