Hi
I've not been doing php for very long, and have a problem referencing the content of arrays using variable variables. To explain using code:
If I have an example masterarray like this:
$masterArray = array("thing","thang","tho
ng");
and three arrays containing the actual data:
$thingArray = array("thing00","thing01",
"thing02",
"thing03",
"thing04",
"thing05")
;
$thangArray = array("thang00","thang01",
"thang02",
"thang03",
"thang04",
"thang05")
;
$thongArray = array("thong00","thong01",
"thong02",
"thong03",
"thong04",
"thong05")
;
My data is stored in an mysql base, each of these items reference a cell, but that isn't important.
For now, let's say that $thangArray["thang03"] = "stuff";.
Now I want to present or store or get these data using a loop. I've tried a whole lot of different ways to do this, and my code currently looks like this:
$numMasterArray = count($masterArray); // as the master array will be expanded over time and I want to change as little code as possible when I do.
for($counter=0; $counter < $numMasterArray; $counter++)
{ for($counter2=0; $counter2 < 6; $counter2++)
{ $test = $masterArray[$counter] . "Array";
echo $$test[$masterArray[$count
er] . str_pad($counter2, 2, "0", STR_PAD_LEFT)];
}
}
I've tried about a fifty different ways to get the echo sentence to display the contents of the "sub"-arrays, but either I suddenly reference $thang00, $thang01 and so on, or I just get thang00, thang01 and so on as text. How can I code this so I get the actual contents of $thangArray["thang00"] etc?
Hopefully I've explained this so you can understand what my problem is.
Start Free Trial