Home  >  Article  >  Backend Development  >  What is the difference between php== and ===?

What is the difference between php== and ===?

青灯夜游
青灯夜游Original
2020-04-24 18:27:093047browse

What is the difference between == and ===? The following article will introduce it to you. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What is the difference between php== and ===?

The difference between === and == in php

===Compare the value and type of two variables; == Compares the values ​​of two variables, not the data types.

For example:

$a = '123';
$b = 123;

$a === $b  //为假;
$a == $b  //为真;

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 will be "The string does not contain ”, which is inconsistent with reality.

For more related knowledge, please pay attention to PHP Chinese website! !

The above is the detailed content of What is the 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