The difference between $array [0] and $array[' 0 ']

Source: Internet
Author: User
Tags integer numbers
The difference between $array [0] and $array[' 0 ']
such as the title $array 0= $array [0] and $array0= $array [' 0 '] can get the first value of the array to distinguish
------to solve the idea----------------------
References:
as long as it is a number, there is no difference between a numeric type and a character type
Var_dump (3.2 = = ' 3.2 '); True



Quote: References:

Quote: References:

Because they're all numbers 0, so there's no difference.


What if we change to 1 2 3?


The return true is because the automatic conversion data type to compare, if you replace with = = = To compare, return is false.

PHP is a weakly typed language that is automatically converted to the appropriate data type at the time of operation.
Just made the next test, and came to the conclusion that:
Quoted integer strings are automatically converted to numbers, indexed as integers, non-integer numbers are not converted, and are still treated as string indexes.
unquoted numbers, non-integers are rounded and then indexed as integers

In addition, a string that is undefined as a constant is indexed, without the quotation marks, although the correct result can be obtained, but there is a warning error.


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