Re: What am I not understanding about $GLOBALS['myvar'] vs global $myvar?
| From: | Leif K-Brooks | Date: | Wed, 26 Mar 2003 22:20:21 +0000 |
| Subject: | Re: What am I not understanding about $GLOBALS['myvar'] vs global $myvar? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141130@lists.php.net to get a copy of this message | ||
No, you misunderstand. The key is simply a string. Just as "print foo;" is wrong, $array[foo] is wrong (unless foo is a constant, of course). If you do "print '$variable';", it will print the literal string "$variable". It will not print the value of $variable. You should either use double quotes or no quotes.
Johnson, Kirk wrote:
I think you either want to use no quotes or double quotes, but not single quotes. Double quotes will interpolate the variable, single quotes will not, i.e. $key becomes a string literal rather than a variable. No quotes will work, although the docs seem to indicate it is deprecated syntax. Not everyone agrees that it is deprecated, though ;) Kirk-- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.$GLOBALS[$key] is incorrect and depricated AFAIK. $GLOBALS['$key'] (with the single quotes) is the proper way to write these types of associative arrays/hashs.