tags:

views:

29

answers:

4

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]"; // DOESN'T WORK

I have tried quotes and double quotes without luck.

Any help?

Thanks

+4  A: 

Try this:

$display_table .= " - {$row['1_year']}";

or you could just do it like this:

$display_table .= ' - ' . $row['1_year'];
RaYell
+1  A: 

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'];

Thirler
In this case the number isn't the problem. Underscore is.
RaYell
+3  A: 
$display_table .= " - " . $row['1_year'];
Mike B
A: 

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.

Phil Sturgeon
How come this be quicker?
RaYell
As i said, double-quotes interpret magical characters, variables, newlines, all sorts of stuff. Single quotes only interpret characters exactly as they are. It's no big deal, but if you code a whole application with doubles instead of singles it will be fractionally slower. http://www.weberdev.com/get_example-3750.html
Phil Sturgeon