php - How to work with $GLOBALS -


i have 2 different php files, , in 1 of file created global array

$globals['system'] = array(     'mysqli' => array(         'host'      => 'localhost',         'username'  => 'root',         'password'  => '',         'database'  => 'database'     ) ); 

how can able use array in file e.g.

$globals['system']['mysql']['host']; 

$globals['system'] = array(); 

this unnecessary. do

$system = array(); 

now, can use $system anywhere want (in other includes, etc), catch functions won't see due scope. means each function doesn't have access $system because it's not in global scope (and that's thing because if needed use $system inside function?) now, can fall

function foo() {      echo $globals['system']; } 

but that's clunky , relies on $system being defined somewhere , not changing. let's inject instead

function foo($system) {      echo $system; } foo($system); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -