The built-in PHP function parse_str( $str ) parses a query string and sets the variables from it into the current scope. Is there any way for me to create my own function that does something like this and returns values to the scope of the caller?
Example:
function checkset()
{
global $inputs;
for( $counter = 0, $varname = func_get_arg($counter), $counter++)
{
if(isset($inputs[$varname]))
{
calling_scope( $varname, $inputs[$varname] );
}
}
return;
}
where calling_scope( $varname, $value) would be a function that sets $$varname in the scope where the function is called to $value. Any help is appreciated.
You can’t inject variables into the calling scope. You however can use
extractto turn the keys/values from an associative array into variables in the local scope. This is probably as close as you’re going to get.