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.