I am very new to programming and I got a job from school to do a "forecast" weather map from random generated numbers.
I already got 7 different arrays for every day (day1 -> day7) and all the code afterwards to check the required stuff and create the weather map.
Now I have the problem that I'd like to go through all the 7 arrays in 1 for-loop. I asked a friend and I think it's a very tiny thing missing / done wrong...
As I already got all the code afterwards (currently hardcoded for 1 day) I'd be pleased if you could provide me a solution for my (I guess crappy) way, not a totally different way eventhough it's most likely much more efficent what so ever.
I tried it like this:
for($daynr = 1; $daynr < 8; $daynr++){
$dayZ = 'day'.$daynr;
print_r($$dayZ);
...
This works like a charm and gives out array 1-7. But when I try to access a part of dayZ I get stuck:
echo $$dayZ[0][0]
Gives out:
Notice: Undefined variable: in C:\xampp\htdocs\index.php on line 139
As many stuff later like $temp = explode('/',$$dayZ[$region_nr][3])...
need to access the day-array it would be cool to have a solution for that.
Btw, something like echo $day1[0][0]
works without problems.
Any help very appreciated, thanks in advance
Best regards
Michael
Use
${$dayZ}[0][0]
Keep in mind that this kind of variable format does NOT improve readability or good code.