note 13888 added to language.types.array.php
| From: | stefan at php2 dot chek dot com | Date: | Sun, 08 Jul 2001 17:06:16 +0000 |
| Subject: | note 13888 added to language.types.array.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15095@lists.php.net to get a copy of this message | ||
If using associative arrays with strings as keys, I would recommend explicitly quoting the keys,
i.e. use $array["$key"] instead of $array [$key]. You might run into trouble with PHP not
finding your array elements if $key is numeric but meant to be an associative key because PHP would
interpret $array [$key] as an access to an indexed array. By quoting you kind of type cast the key
to a string.
I'll give an example to clarify:
Define
$a ["abc"] = "one";
$a ["234"] = "two";
Now try:
print $a ["abc"] works as expected
print $a ["234"] works as expected
but print $a [234] will *not*
Maybe this should be added to the manual somewhere.
Steve
http://www.php.net/manual/en/language.types.array.php