Re: Odd behaviour of non-existent keys?
| From: | John Holmes | Date: | Wed, 25 Aug 2004 12:54:02 +0000 |
| Subject: | Re: Odd behaviour of non-existent keys? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194674@lists.php.net to get a copy of this message | ||
From: "Geoff Caplan" <geoff@variosoft.com>
Getting a result I don't understand. Why does the non-existent key in the array below evaluate to the first char of the array value? $foo = '' ; $foo['one']['two'] = 'test-value' ; // Evaluates to: string(1) "t" var_dump( $foo['one']['two']['three'] ) ; // Evaluates to NULL, as expected var_dump($foo['one']['two']['three']['four'] ) ; Can anyone enlighten me?Strings are arrays. PHP probably takes the string 'three' and converts it to a integer to see what "key" of the string you're requesting. $foo = 'bar'; echo $foo[1]; //should echo 'a' Does that help or do you need a deeper explanation (that I probably can't provide!) ;) ---John Holmes...