Sometimes the judgment will find if (!a==b) and if (a!=b) unexpectedly has the difference;
A few times using the previous method did not get the results I want, want to ask the difference between the two.
Add:
Sorry, I wrote it wrong before.
Should there be a difference between a!=b and!a==b?
(Is it not the same as before, because of their own mistakes?!) )
Reply content:
Sometimes the judgment will find if (!a==b) and if (a!=b) unexpectedly has the difference;
A few times using the previous method did not get the results I want, want to ask the difference between the two.
Add:
Sorry, I wrote it wrong before.
Should there be a difference between a!=b and!a==b?
(Is it not the same as before, because of their own mistakes?!) )
Did you write the wrong landlord? Note Yes ! $a == $b
, not! $a = $b
Although the precedence of the PHP operator is !
higher than =
the priority, it allows a very strange syntax, that is, the assignment will be ! $a = $b
given first, $b
$a
and then the statement will ! $a
always return the $b == false
same result. and $a != $b
not at all comparable.
And ! $a == $b
the words should be the $a != $b
same ...
Add, according to my understanding ! $a == $b
should be and $a != $b
the effect is the same, temporarily did not think of a different special case, but there are many values in PHP and Boolen have the same meaning, there are inevitably some in the conversion of the occurrence of the special circumstances you say. Make a list of PHP and false equivalents:
The Boolean value FALSE itself
Integer value 0 (0)
Floating-point value 0.0 (0)
An empty string, and the string "0"
An array that does not include any elements
Objects that do not include any member variables (PHP 4.0 only applies)
Special type NULL (including variables that have not been assigned)
SimpleXML object generated from an empty tag
For example $a = 0
, $b = 1
then:
$a = $b
is 1,!1 is false, so if (! $a = $b) is False
$a != $b
Yes 1! = 0 is obviously true
if (! $a = $b) is equivalent to if (! ( $a = $b)).
By the way, which teacher teaches you this kind of writing?
A! = B
!a = b
An equal sign is a value assignment.
Code style is important
// a和b作为字符串, 两者值应该是不相等的; 但是他们对应的布尔值都是false$a = '0';$b = '';$a != $b; // true!$a == $b; // false
The output is as follows