I've been trying to work with two for-loops to iterate through a multidimensional array and to assign the values to individual variables. However, it doesn't work, because it seems that I can't get the variables assigned to the data.
$onepage = array
(
array("navbar",22,28,23,25),
array("presentation",15,13,23,23),
array("content",5,2,13,10),
array("footer",17,15,23,26)
);
function presetter($selection) { //selection = onepage
for($n=0;$n<=3;$n++){
for($i=1;$i<=4;$i++){
$rwcl = $selection[$n][0];
$numb = $i -1;
${$rwcl . $numb} = $selection[$n][$i]; //outputs navbar1
$l = $rwcl . $numb;
$$l = $selection[$n][$i];
echo ${$rwcl . $numb}; //outputs variable navbarx
echo $rwcl;//output column name
echo $selection[$n][$i];
echo "<br>";
}
}
} //<-- works!
presetter($onepage);
echo $navbar1;
The output is always Type 8 - undefined variable. I've tried several options, also the proposed solution here: PHP: Create Unique Variables In A For Loop, but without a positive result.
Probably some will say that what I do is not the sense of arrays. And yes, you are right. But would like solve it.
Maybe somebody knows how to get it done. Thanks in advance.