views:

817

answers:

5

I saw

if($output !== false){
}

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

+18  A: 

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:

CMS
+2  A: 

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

So !== is (not ===)

Svetlozar Angelov
A: 

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.

Marius
+1  A: 

!== 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.

zombat
+1  A: 

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.

PatrikAkerstrand