while($assocArray = mysql_fetch_assoc($result))
{
for ($j = 0; $j < $length; $j++)
{
$column = $fields[$j]; // + works
echo "$assocArray[$column] "; // +
//echo "$assocArray[ $fields[$j] ] "; // - doesn't work, should be same
}
echo "<br/>";
}
A similar problem was reported for numeric arrays, which supposedly was solved. I’m using a very new build of PHP (5.3.6) so it must be a separate bug. Generates parse error.
Surround the whole expression with curly braces:
FYI: This is partially a matter of taste, but personally, I prefer not inlining arrays, especially with nested arrays. Isn’t this nicer?