The usage difference of congruent = = = and equal = = in PHP

Source: Internet
Author: User
Differences in usage of congruent (= = =) and equality (= =) in PHP

Let's take a look at the following program: $STR = "0d52"; If (0== $str) {echo "true"} Else {echo "false"}

The result of this program running unexpectedly, "0d52" actually by PHP think and 0 equal. Why is there such a situation? The execution of the relational operation "= =" requires that the data types on both sides of the operator must be identical, so that the string to the right of the equal sign is cast for integral type 0.

This is the disadvantage of many weakly typed languages. This kind of mistake is not tolerated in our procedure, is there any way to solve this problem? The answer, of course, is yes, and in PHP we are provided with all equal to solve similar problems.

Now we're going to rewrite the program into the following form to explain how all equals works. $str = "0d52"; If (0=== $str) {echo "true"} Else {echo "false"}

All equal to the operation process is as follows: 1. Determine if the data type is equal to the operator 2 edge if it is not the same, then return False 2. Determines whether the values of all equals operator 2 are equal and returns false 3 if not equal. Finally, the above 2 steps are performed and manipulated. Returns the result of the operation.

Not all equal to the operation process is exactly equal to the opposite: 1. The judgment is not equal to the same as the data type of the operator 2 edge if it is not the same, True 2 is returned. The judgment is not equal to the value of the 2 side of the operator, or true 3 if not equal. Finally, the above 2 steps are performed or manipulated. The result of the return or operation.

All right, PHP is equal to not all equal to the completion of the explanation, I hope that the reader of PHP enthusiasts have benefited!

The above describes the php equality = = = and Equal = = usage differences, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.