Re: unsetting global variables from an function

From: Date: Thu, 28 Feb 2002 07:54:12 +0000
Subject: Re: unsetting global variables from an function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86549@lists.php.net to get a copy of this message
In article <20020228084437.B1221@metux.de>, weigelt@metux.de (Enrico Weigelt) wrote: > is there a way for unsetting an global variable from an function ? > > global $var; unset ( $var ); > > does not work since, unset only removes the reference in from > local namespace. but i need to remove it from the global one. > > any chance to do it ? Instead of using the 'global' keyword, use the $GLOBALS array: $var='foobar'; function gUnset() { echo "BEFORE: {$GLOBALS['var']}"; unset($GLOBALS['var']); echo "AFTER: {$GLOBALS['var']}"; } gUnset(); -- CC

« previous php.general (#86549) next »