Let’s say I have this array,
$array = array(
'name' => 'hermet',
'emails' => array ('hermet@example.com',
'hermet@example.net');
);
So this way echo $array ['name'] == 'hermet' prints true. I would like to know if there is a function already embedded in PHP that let me do this:
echo $name == 'hermet'; // obviously 'false'
foreach ($array as $key => $value) {
$aux = $key;
$$aux = $value;
}
echo $name == 'hermet'; // now prints 'true'
It seems to work even with a multidimensional array but I don’t know if PHP has already any function to do that.
Thank you in advance.
You might be looking for extract
— EDIT: If you are concerned about Paul’s remark, supply EXTR_SKIP to the second argument of extract, that way it won’t overwrite variable in case you’ve already defined it prior to calling extract.