What does !== comparison operator in PHP mean?

11,307

Solution 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:

Solution 2

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

So !== is (not ===)

Solution 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.

Solution 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.

Solution 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.

Share:
11,307

Related videos on Youtube

Thejesh GN
Author by

Thejesh GN

{Thejesh GN ⏚ ತೇಜೇಶ್ ಜಿ.ಎನ್} Hacker, Maker, Blogger, InfoActivist, Developer, Web, Free & Open SW/HW/Data/Internet, Traveller, 0xBFFC8DD3C06DD6B0 @thej on Twitter My Blog

Updated on April 19, 2022

Comments

  • Thejesh GN
    Thejesh GN 30 days

    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?