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
Post a Comment