1

What does this !== mean in php and is there any doc's on it?

HELP
  • 13,677
  • 19
  • 63
  • 100

5 Answers5

7

PHP comparison operators, "Not identical" (5th in the table)

This operator works much like != but also checks the type of the operands. For example: 3 != '3' is false, but 3 !== '3' is true.

Jon
  • 413,451
  • 75
  • 717
  • 787
5

== is the comparison operator you're familiar with: if two values are equivalent, they == each other. There's some type coercion that goes on before the comparison.

4 == '4' // true: equivalent value, different type

=== is a more strict comparison that requires that values be of the same type.

4 === 4 // true: same value, same type
'4' === '4' // true: same value, same type
4 === '4' // false: equivalent value, different type

!== is the opposite of the strict comparison operator, so it is true when two values are of a different type or different value or both.

4 !== 3 // true: different value, same type
4 !== '4' // true: equivalent value, different type
'4' !== 3 // true: different value, different type
'4' !== '3' // true: different value, same type
4 !== 4 // false: same value, same type
Matchu
  • 80,913
  • 16
  • 150
  • 159
2

It means "not equal or not the same type".

This shows the difference between != and !==:

"5"!=5 //returns false
"5"!==5 //returns true
thejh
  • 43,352
  • 16
  • 93
  • 105
1

That is the not identical operator

$a !== $b

Returns TRUE if $a is not equal to $b, or they are not of the same type.

For example, it is used to check if a variable is false and not 0, since 0 is the same that false for PHP.

$bar = 0;
if ($bar != false) { echo '$bar != false'; } // won't output the text
if ($bar !== false) { echo '$bar !== false'; } // will output the text
NeDark
  • 1,233
  • 6
  • 23
  • 35
  • Indeed, particularly useful if a function can return an resulting integer on success or false on failure. You will need to check "!== false" as "!= false" could be success and returning the integer 0; – drew Nov 27 '10 at 11:51
0

!= is used for value only but !== is used for value and type both

suppose:

$a = "5"; // String
$b = 5;   // Integer

$a!=$b    // false
$a!==$b   // true

That's the difference.