note 27546 added to language.variables.scope

From: Date: Tue, 10 Dec 2002 15:03:23 +0000
Subject: note 27546 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-40659@lists.php.net to get a copy of this message
Becareful where you define your global variables: This will work: <?php $MyArray = array("Dog"); function SeeArray(){ global $MyArray; if (in_array("Dog",$MyArray)){ foreach ($MyArray as $Element){ echo "$Element <hr/>"; } } } SeeArray(); ?> while this will not: <?php SeeArray(); $MyArray = array("Dog"); function SeeArray(){ global $MyArray; if (in_array("Dog",$MyArray)){ // an error will generate here foreach ($MyArray as $Element){ echo "$Element <hr/>"; } } } ?> -- http://www.php.net/manual/en/language.variables.scope.php http://master.php.net/manage/user-notes.php?action=edit+27546 http://master.php.net/manage/user-notes.php?action=delete+27546 http://master.php.net/manage/user-notes.php?action=reject+27546

« previous php.notes (#40659) next »