I have this function:
function extractAvailable($assoc1, $assoc2){
if($assoc1) extract($assoc1);
else extract($assoc2);
}
What I expect is to call this function later in the global scope, and have my variables available, like so:
$arr1 = [];
$arr2 = ['one'=>1, 'two'=>'SecondItem'];
extractAvailable($arr1, $arr2);
With the call on extractAvailable()
, I need to have the varialbes $one
and $two
available in the current scope. Obviously, I've got something wrongly figured concerning variable scope use here, 'cause it isn't working. When I try to use the variable, what I get instead is Notice: Undefined variable: one
.
How do I get this to work?