Deep PHP to use double equals (= =) in the detailed _php skills

Source: Internet
Author: User

PHP comparison operators appear to be too often, especially = =
if (a = = b) {
Do something
}
But have you really mastered the = =? The details are important!
Look at the code below and say what you think is the right answer.
Var_dump (' 123fg456 ' ==123);
Var_dump (' some string ' = 0);
Var_dump (123.0 = = ' 123d456 ');
Var_dump (0 = "a");
Var_dump ("1" = = "01");
Var_dump ("1" = = "1e0");
Think of your answer first, then run it again. If the answer is not wrong, then congratulations, the basic knowledge is very solid.

Explain:
If you compare an integer and a string, the string is converted to an integer. If two numeric strings are compared, they are compared as integers. This rule also applies to switch statements.
It is particularly noted that when a string is converted to an integer, it is left to right until a non-numeric character is encountered. That means ' 123abc456 ' will be converted to 123 instead of 123456. Another space that starts with a string is ignored, such as ' 234abc ' converted to 234.
Below are a list of loosely compared and strictly compared tables

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.