PHP converts numeric keys to integers when creating an array element. These are not array_keys
. But there is a hack for getting string numeric keys:
$a = new stdClass; $a->{"0"} = "zero"; $a = (array) $a; var_dump($a);
Output:
array(1) { ["0"]=> string(4) "zero" }
But you will not be able to access this key by index, so it is not very useful.
If you must have string keys, you will need to prefix them with another non-numeric (or null) character:
$MNTH["001"] = "January"; $MNTH["012"] = "December";
From the documentation :
The key can be an integer or a string. If the key is a standard representation of an integer, it will be interpreted as such (i.e., "8" will be interpreted as 8, and "08" will be interpreted as "08"). The floats in the key are truncated to the whole. Indexed and associative array types are the same type in PHP, which can contain both integer and string indexes.
source share