short php syntax error, help
I have this in php code:
$display_table .= " - $row[year]";
Works fine!
But when I try it with another row, it wont work:
$display_table .= " - $row[1_year]"; // D开发者_StackOverflow社区OESN'T WORK
I have tried quotes and double quotes without luck.
Any help?
Thanks
Try this:
$display_table .= " - {$row['1_year']}";
or you could just do it like this:
$display_table .= ' - ' . $row['1_year'];
$display_table .= " - " . $row['1_year'];
Probably this is because you can't start the key with a number (in this case).
The best way to use variables in a string is by concattenating. This prevents errors like yours.
$display_table .= " - ".$row['1_year'];
or this:
$display_table .= ' - ' . $row['1_year'];
It is much quicker. Double quotes and using { is slower in PHP than using single quotes and escaping strings. The reason double quotes are slower is that it has much more to potentially interpret than single quotes, which are literal.
精彩评论