Jump to content

[SOLVED] Dynamic Variables in $GLOBALS


electricshoe

Recommended Posts

Heya I'm trying to set a dynamic variable as a global in a function. It's a simple function that takes a $result from a mysql query and gets the array with a custom variable name.

 

function queryData($data)
{
$GLOBALS[$data] = mysql_fetch_array($GLOBALS['result']);
}
queryData("customRowName");

echo $customRowName['id'];

 

This code doesn't work. The query is fine, I can do print_r($GLOBALS[$data]) and it returns my array.

 

I've tried $GLOBALS[${$data}] and it doesn't work either. I'm getting a notice that the variable is unset for both of them

 

Notice: Undefined variable: customRowName in ---- on line 20

 

Any help would be greatly appreciated, thanks:)

Link to comment
https://forums.phpfreaks.com/topic/71702-solved-dynamic-variables-in-globals/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.