I needed this once, but I could not figure out how to just create the vars
in current scope.
If my_extract() is called from within a function, then the variables will
not be available unless you declare them global (which kinda makes the
function pointless).
Any ideas?
-Jason Garber
There is this array which I would like to convert into a series variables using the
extract function:
?
$oz = array(
lion = courage,
dorothy = kansas,
scarecrow = brain
tin man = heart);
extract($oz);
?
now, I would like to access my new variables. it is obviously easy for $lion,
You may want to do something like this instead:
?
function my_extract($arr)
{
if(is_array($arr) sizeof($arr))
{
while(list($key,$val) = each($arr)
{
$new_var = str_replace(' ','_',$key);
global $$new_var;
$$new_var = $val;
}
}
}
?
3 matches
Mail list logo