Storage Rules of phparraykey

Source: Internet
Author: User
The storage rules of phparraykey have just encountered the php array Fetch & #20540; problem, and found that the strings and numbers are the same. The key can be an integer or string. Value can be of any type. In addition, the key has the following mandatory conversions: strings containing valid integer & #20540; will be converted to integer. For example, the storage rules of the key php array key

When I was writing a program and encountered the php array value problem, I found that the strings and numbers are the same.


The key can be an integer or string. Value can be of any type.

In addition, the key will have the following forced conversion:

  • A string containing valid integer values is converted to an integer. For example, key name"8"Actually stored8. However"08"It is not forcibly converted because it is not a valid decimal value.
  • The floating point will also be converted to an integer, meaning that the fractional part of the floating point will be removed. For example, key name8.7Actually stored8.
  • The Boolean value is also converted to an integer. That is, the key name.TrueActually stored1Key nameFalseWill be stored0.
  • Null is converted to a Null string, that is, the key name.NullActually stored"".
  • Array and objectNoUsed as the key name. Sticking to this will cause a warning:Illegal offset type.

If the same key name is used for multiple cells in the array definition, only the last one is used, and the previous one is overwritten. The result is the same with an integer or a string.

$array = array(
    1    => "a",
    "1"  => "b",
    1.5  => "c",
    true => "d",
);

$array[1] and$array["1"],$array[True] d is returned, because d overwrites the previous value, and key1, "1", true, is 1 in the interpreter, so it 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.