note 61756 modified in language.variables.scope by danbrown

From: Date: Mon, 18 May 2009 01:36:50 +0000
Subject: note 61756 modified in language.variables.scope by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155563@lists.php.net to get a copy of this message
If you want to access a table row using $GLOBALS, you must do it outside string delimiters or using curl braces : <?php $siteParams["siteName"] = "myweb"; function foo() { $table = $GLOBALS["siteParams"]["siteName"]."articles"; // OK echo $table; // output "mywebarticles" $table = "{$GLOBALS["siteParams"]["siteName"]}articles"; // OK echo $table; // output "mywebarticles" $table = "$GLOBALS[siteParams][siteName]articles"; // Not OK echo $table; // output "Array[siteName]article" $result = mysql_query("UPDATE $table ..."); } ?> Or use global : <?php function foo() { global $siteParams; $table = "$siteParams[siteName]articles"; // OK echo $table; // output "mywebarticles" $result = mysql_query("UPDATE $table ..."); } ?> --was-- If you want to access a table row using $GLOBALS, you must do it outside string delimiters or using curl braces : $siteParams["siteName"] = "myweb"; function foo() { $table = $GLOBALS["siteParams"]["siteName"]."articles"; // OK echo $table; // output "mywebarticles" $table = "{$GLOBALS["siteParams"]["siteName"]}articles"; // OK echo $table; // output "mywebarticles" $table = "$GLOBALS[siteParams][siteName]articles"; // Not OK echo $table; // output "Array[siteName]article" $result = mysql_query("UPDATE $table ..."); } Or use global : function foo() { global $siteParams; $table = "$siteParams[siteName]articles"; // OK echo $table; // output "mywebarticles" $result = mysql_query("UPDATE $table ..."); } http://php.net/manual/en/language.variables.scope.php

« previous php.notes (#155563) next »