Home >Backend Development >PHP Tutorial >Difference between PHP == and ===

Difference between PHP == and ===

Guanhui
GuanhuiOriginal
2020-06-04 18:28:063941browse

Difference between PHP == and ===

The difference between PHP == and ===

In PHP, "==" and "===" both mean judgment Whether two values ​​are equal, the difference between the two is that "===" compares the values ​​​​and types of two variables, while "==" compares the values ​​​​of two variables without comparing data types. Compared with the latter, the two The former is inspected more strictly.

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.

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of Difference between PHP == and ===. 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
Previous article:Get started with PHP-FPMNext article:Get started with PHP-FPM