What does !== comparison operator in PHP mean?

南笙酒味 提交于 2020-01-02 00:52:23

问题


I saw

if($output !== false){
}

It's an exclamation mark with two equals signs.

It almost works like not equal. Does it has any extra significance?


回答1:


They are the strict equality operators ( ===, !==) , the two operands must have the same type and value in order the result to be true.

For example:

var_dump(0 == "0"); //  true
var_dump("1" == "01"); //  true
var_dump("1" == true); //  true

var_dump(0 === "0"); //  false
var_dump("1" === "01"); //  false
var_dump("1" === true); //  false

More information:

  • PHP Comparison Operators



回答2:


PHP’s === Operator enables you to compare or test variables for both equality and type.

So !== is (not ===)




回答3:


!== checks the type of the variable as well as the value. So for example,

$a = 1;
$b = '1';
if ($a != $b) echo 'hello';
if ($a !== $b) echo 'world';

will output just 'world', as $a is an integer and $b is a string.

You should check out the manual page on PHP operators, it's got some good explanations.




回答4:


See this question: How do the equality (==) and identity (===) comparison operators differ?.

'!==' is the strict version of not equal. I.e. it will also check type.




回答5:


yes, it also checks that the two values are the same type. If $output is 0, then !== will return false, because they are not both numbers or booleans.



来源:https://stackoverflow.com/questions/1298083/what-does-comparison-operator-in-php-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!