Home  >  Article  >  Backend Development  >  The difference between === and == in php

The difference between === and == in php

藏色散人
藏色散人Original
2020-05-17 11:25:154194browse

The difference between === and == in php

The difference between === and == in php

===Compare the sum of the values ​​of two variables Type; == compares the values ​​of two variables, not the data types.

For example $a = '123';

$b = 123;

$a === $b is false;

$a == $b is true;

In some cases you cannot use ==, you can use ===, for example:

<?php
$a = &#39;abc&#39;;
$b= &#39;a&#39;;
if(strpos($a,$b) === false){
    echo &#39;字符串不包含&#39;;
}else{
    echo &#39;字符串包含&#39;;
}
?>

If you use = =, the output "string does not contain" is inconsistent with the actual situation.

Note:

= is an assignment, for example:

$a=2;$a=$q; at this time, whether you echo $a or echo $q, it will be output 2

The above is the detailed content of The difference between === and == in php. 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