Jump to content

How to use variables outside of a function without globaling each one?


Jakez

Recommended Posts

Ok let's say I am loading settings from MySQL into varibles like so:

$result=mysql_query("SELECT * FROM table WHERE id='1' LIMIT 1");
while($row=mysql_fetch_array($result))
{
  $path=$row['path'];
  $etc=$row['etc'];
}

 

Then I have a function:

 

function func_name()
{
  global $path, $etc;
  print $path.$etc;
}

 

Is there a way to "pre" global these variables so that I can use them in all my functions without having to global them inside each function? I have a lot of variables loaded in the settings and I'd rather not have to global them in every function.

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.