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.