note 17521 added to language.variables.scope
| From: | jeremy dot hilton at hostcentric dot com | Date: | Wed, 12 Dec 2001 18:55:30 +0000 |
| Subject: | note 17521 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-22554@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;
--
http://www.php.net/manual/en/language.variables.scope.php
http://master.php.net/manage/user-notes.php?action=edit+17521
http://master.php.net/manage/user-notes.php?action=delete+17521
http://master.php.net/manage/user-notes.php?action=reject+17521