Access local variable in function from outside function (PHP) -
is there way achieve following in php, or not allowed? (see commented line below)
function outside() { $variable = 'some value'; inside(); } function inside() { // possible access $variable here without passing argument? }
its not possible. if $variable
global variable have access global
keyword. in function. can not access it.
it can achieved setting global variable by$globals
array though. again, utilizing global context.
function outside() { $globals['variable'] = 'some value'; inside(); } function inside() { global $variable; echo $variable; }
Comments
Post a Comment