At the time of writing the procedure $a = = 2 and 2 = = $a what is the difference
Reply content:
At the time of writing the procedure $a = = 2 and 2 = = $a what is the difference
For languages that can be assigned to a value in a conditional operator, you can avoid the problem of omitting the equals sign by placing the constant before the comparison operator.
That is to say, this avoids the problems that are $a == 2
written by our various mistakes $a = 2
.
This technique is not very useful in PHP, but is relatively large in the Java Web, such as determining whether a user-submitted parameter A is equal to the string "ABC"
Use "abc".equals(a)
is better a.equals("abc")
, because a may be empty, the latter will be an error, and the former can give the correct result.
2== $a have not seen such a writing, if possible, please enlighten?
It's not a big effect.
The main purpose is to prevent the judgment from being less than one equals sign.
Suppose $a=1;
2== $a;//can be executed with a value of false
2= $a;//Save
$a ==2;//can be executed with a value of false
$a =2;//can execute with a value of true because it is an assignment statement
$a = = 2 less an equal sign is an assignment operation, and the compiler does not prompt an error
2 = = $a less an equal sign the compiler will prompt an error
The premise is that when you do a comparison operation in the IF
No difference.
However, $a = = 2 in the sense of language easier to accept a little