I have a multidimensional array and I want to create new variables based on the keys.
I have written this code, but it returns NULL:
$a = array("test" => array("a", "b", "c"));
foreach($a as $key => $value){
if(is_array($value)){
$i = 0;
foreach($value as $v){
$i++;
$$key[$i] = $v;
}
}
}
var_dump($test);
?>
Where is the problem?
Make that:
$$key[$i]means “the variable whose name is$key[$i]“.${$key}[$i]means “position$ifrom the variable whose name is$key“.Also, it would be nice if you could initialize that
$testarray, so you won’t get notices. Add the following before the secondforeach: