Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Difference between !== and ==! operator in PHP
In PHP, !== and ==! may look similar but behave very differently. !== is a single operator (strict not-equal), while ==! is actually two operators combined: the equality operator == followed by the logical NOT ! applied to the right operand.
!== (Strict Not-Equal Operator)
The !== operator is a single comparison operator that checks if two values are not equal OR not of the same type. It does not perform type conversion. For example, 1 !== '1' returns true because the types differ (integer vs string).
// !== checks value AND type var_dump(1 !== '1'); // true (different types) var_dump(1 !== 1); // false (same value and type) var_dump(true !== false); // true (different values)
==! (Two Separate Operators)
==! is not a single operator. PHP interprets it as == (loose equality) followed by ! (logical NOT) applied to the right operand. So $x ==! $y is the same as $x == (!$y).
// ==! is parsed as == (!operand) // $x ==! $y is same as $x == (!$y) var_dump(true ==! false); // true == (!false) => true == true => true var_dump(false ==! true); // false == (!true) => false == false => true
Key Differences
| Feature | !== (Strict Not-Equal) | ==! (Equality + NOT) |
|---|---|---|
| Is a Single Operator? | Yes | No (two operators: == and !) |
| Equivalent To | $x !== $y |
$x == (!$y) |
| Type Check | Yes (strict comparison) | No (loose equality after negation) |
true __ false |
true (different values) |
true (true == !false => true == true) |
Example
The following example shows both operators and a case where they produce different results ?
<?php
$x = true;
$y = false;
echo "!== operator: ";
var_dump($x !== $y); // true !== false => true
echo "==! operator: ";
var_dump($x ==! $y); // true == (!false) => true == true => true
// Case where they differ
$a = 0;
$b = 1;
echo "
0 !== 1 : ";
var_dump($a !== $b); // true (0 is not identical to 1)
echo "0 ==! 1 : ";
var_dump($a ==! $b); // 0 == (!1) => 0 == false => true (loose)
?>
The output of the above code is ?
!== operator: bool(true) ==! operator: bool(true) 0 !== 1 : bool(true) 0 ==! 1 : bool(true)
Conclusion
!== is a proper strict inequality operator that checks both value and type. ==! is not a real operator − it is == combined with !, meaning "is equal to the negation of." They can produce the same result in some cases but have fundamentally different logic. Always use !== for strict inequality comparisons.
