php - set variables to global scope within a loop -
i want define number of temporary global variables in php called $myglobalvar1
, $myglobalvar2
... , problem keyword 'global' takes variable name literally:
for ($i = 1; $i<= 10; $i++) { $var = '$myglobalvar'.$i; global $var; }
i.e. $var
global.
setting quotes not work because 'global' expects '$' , stop execution @ single quote:
for ($i = 1; $i<= 10; $i++) { $var = '$myglobalvar'.$i; global '$var'; }
how set variables global scope? thanks.
since using '
taken string
try $globals purpose
for ($i = 1; $i<= 10; $i++) { // acess $globals['myglobalvar'.$i] , whatever want $globals['myglobalvar'.$i] = null }
Comments
Post a Comment