I am currently working on a somewhat private project of mine, when I discovered something weird. I extracted info from mye mysql-database and stored it in arrays where i generated the names like this:
for ($a = 1; $a <= 4; $a++) {
$result = mysql_query ("select field from table where field = '".$a."'");
$arr = "group".$a;
$$arr = array ();
while ($rad = mysql_fetch_array ($result)) {
array_push ($$arr, $rad["KlanID"]);
}
$arr_keys = array_rand ($$arr, 8);
foreach ($arr_keys as $letter_key => $key) {
echo $$arr[$key];
}
}
The strange thing was that echo $$arr[$key]; printed nothing! print_r ($$arr) showed me the contents of the array, as you would expect. This is how i worked my way around this:
foreach ($arr_keys as $letter_key => $key) {
$arr_copy = $$arr;
echo $arr_copy[$key];
}
echo $arr_copy[$key]; prints the contents correctly. Now - why is that? Is there some issue with $$arr[$key] that I ought to know about, or is it simply a bug in php?
This wasn't actually a problem, as I got this working all right. Just wanted to know why the array-copying is necessary.