note 17521 deleted from language.variables.scope by jimw
| From: | jimw@php.net | Date: | Thu, 20 Dec 2001 23:45:13 +0000 |
| Subject: | note 17521 deleted from language.variables.scope by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23591@lists.php.net to get a copy of this message | ||
Here is a tip on using $GLOBALS. If you set an element of the $GLOBALS array equal to an array, you
might have problems calling those variables. Below is an example.
//declare array
$list = array("ex1"=> "example1", "ex2"=> "example2");
//set example element of GLOBALS array equal to lis array
$GLOBALS[example] = $list;
//Now if you try to print
print $GLOBALS[example][ex1];
//You get "example1" returned
//as expected
//But id you try to print
//the same thing, but enclosed
//in double quotes
print "$GLOBALS[example][ex1]";
//You get "Array[ex1]";
//Enclosing in double quotes
//somehow screws up the expansion
//of that variable
//You must instead
print "{$GLOBALS[example][ex1]}";
//enclose the variable in curly braces
//this returns "example1" as expected;