I have a bizarre issue that I cannot for the life of me seem to resolve.
I am generating an array ($tags) from a mysql query, it looks something like this:
Array(
[1] => Safety Toe
[2] => Waterproof
)
Then I have another array ($link) I generate in a loop:
Array(
[1] => Array(
[0] => 1
[1] => 2
)
[2] => Array(
[0] => 1
[1] => 2
)
)
Also, I have 2 predefined variables that in this case are as follows:
$max == 2;
$title_count == 3;
Later on I have 2 for loops, 1 is nested:
for($y=0;$y<$max;$y++){
for($x=1;$x<=$title_count;$x++){
if($x==1){
echo "<tr><td>".$tags[$link[$x][$y]]."</td>";
}elseif($x<$title_count){
echo "<td>".$tags[$link[$x][$y]]."</td>";
}else{
echo "<td>".$tags[$link[$x][$y]]."</td></tr>";
}
}
}
This should produce something along the lines of:
Safety Toe Safety Toe Safety Toe
Waterproof Waterproof Waterproof
The problem is this is what I get:
Safety Toe Safety Toe Safety Toe
This made me curious, so I tried manually inputting $tags[2]. That worked and produced:
Waterproof Waterproof Waterproof
Waterproof Waterproof Waterproof
However, if I manually set them all to $tags[$link[1][1]] ($link[1][1] == 2) I get an empty result. If I set a variable, such as $test = $link[1][1]; (which echoes as 2), and then try $tags[$test], I get nothing. However if I set $test = 2; and do $tags[$test] I get Waterproof.
I am beyond bewildered here, if there is anything I'm missing, or any ideas as to why this would be the way it is, please let me know.
Thanks!
$test=$links[1][0]
should be$test=$link[1][0]
, but I guess that will not solve your problem.. – Pieter Jul 9 '13 at 21:00