Storage rules for PHP array key

Source: Internet
Author: User
Tags array definition
Storage rules for PHP array key

Just write the program encountered the problem of PHP array value, found that the string and number of words taken out is the same.


key can be an integer or string. value can be of any type.

In addition, key will have the following casts:

    • A string containing a valid integer value is converted to an integral type. For example , the key name "8" will actually be stored as 8. However, "a" does not cast because it is not a valid decimal value.
    • Floating-point numbers are also converted to integers, meaning that their fractional parts are removed. For example, the key name 8.7 will actually be stored as 8.
    • Boolean values are also converted to integral types. That is, the key name true is actually stored as 1 and the key name false is stored as 0.
    • null is converted to an empty string, that is, the key name null is actually stored as " ".
    • Arrays and objects cannot be used as key names. Insisting on doing so will result in a warning:illegal offset type.

If more than one cell in the array definition uses the same key name, only the last one is used, and the previous is overwritten. The result is the same as an integer or a string effect.

$array = Array (
1 => " a " " 1 " => "B" ,
1.5 => "C" true = > "D" ,
);

$array[1] and $array ["1"], $array [true] return is D, because D overrides the previous value, and Key1, "1", true, the interpreter appears to be 1, so is the same.


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