Is there a difference between !==
and !=
in PHP?
$b - Check if the value of $a is not equal to $b. However, with $a !== $b, the value of $a is matched with $b, and also the 'Type' which must be same. == check for value and === checks for value of same types on both operands.
PHP's === Operator enables you to compare or test variables for both equality and type. So !== is (not ===) Copy link CC BY-SA 2.5.
means that two variables are being checked for both their value and their value type ( 8!== 8 would return false while 8!== "8" returns true). != only checks the variable's value ( 8!=
!= operatorThe inequality operator (!=) is the logical opposite of the equality operator. It means “Not Equal” and returns true where equality would return false and vice versa. Like the equality operator, the inequality operator will convert data types of values while comparing. For example 1 !=
The !=
operator compares value, while the !==
operator compares type as well.
That means this:
var_dump(5!="5"); // bool(false)
var_dump(5!=="5"); // bool(true), because "5" and 5 are of different types
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With