According to manual :
The key can be an integer or a string. The value can be of any type.
In addition, the following keystrokes will be performed:
- Lines containing real integers will be cast from the integer type. For example. the key β8β will actually be stored under 8. On the other hand, β08β will not be selected, since it is not a valid decimal integer.
- The floats also cast from integers, which means that the fractional part will be truncated. For example. key 8.7 will actually be stored under 8.
- Bools are also passed in integers, i.e. the true key will actually be stored under 1 and the false key under 0.
- Null will be passed to an empty string, i.e. the null key will actually be stored under the "" symbol.
- Arrays and objects cannot be used as keys. This will result in a warning: type of invalid offset.
Leadership:
A string is a series of characters where the character matches a byte. This means that PHP only supports 256-character typing and, therefore, does not offer native Unicode support. More on string type.
In short, any string can be a key. And the string can contain any binary data (up to 2 GB). Therefore, a key can be any binary data (since a string can be any binary data).
Some random (actual) abuse of array keys:
$w = array(chr(0) => 'null byte?', chr(rand(0, 255)) => 'random byte?'); var_dump($w);
Corbin May 22 '12 at 5:21 2012-05-22 05:21
source share