At the time of writing the procedure $a = = 2 and 2 = = $a what is the difference

Source: Internet
Author: User
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.