RE: [PHP] What am I not understanding about $GLOBALS['myvar'] vs global $myvar?
| From: | Daevid Vincent | Date: | Wed, 26 Mar 2003 21:50:56 +0000 |
| Subject: | RE: [PHP] 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-141126@lists.php.net to get a copy of this message | ||
Actually I didn't. ;-)
$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.
For shits and giggles however I tried your way and it made no difference to
the code. Still didn't work right.
> -----Original Message-----
> From: Marek Kilimajer [mailto:kilimajer@webglobe.sk]
> Sent: Wednesday, March 26, 2003 1:16 PM
> To: Daevid Vincent
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] What am I not understanding about
> $GLOBALS['myvar'] vs global $myvar?
>
>
>
>
> Daevid Vincent wrote:
>
> >This one does NOT work the way I would expect it to?
> >
> > function clearContactVars()
> > {
> > foreach ($GLOBALS as $key => $value) {
> > if ( substr($key,0,8) == "contact_" ) {
> > //echo "GLOBALS['$key'] = $value<br>\n";
> > $GLOBALS['$key'] = "";
> >
> I did not read your whole message, but you very likely mean
>
> $GLOBALS[$key] = "";
> (no single quotes)
>
> > }
> > }
> > clearPostVars();
> > }
> >
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>