> -----Original Message-----
> From: Phil Schwarzmann [mailto:[EMAIL PROTECTED]]
> Sent: 28 January 2002 22:02
> I keep getting parse error with this code:
> ($teams[] is a big array that I got by using mysql_fetch_array)
>    $r = "game";
>    echo "<select name='game'>";
>    echo "<option value=game1>$teams[$r.'1']</option>";
>    echo "<option value=game1>$teams[$r.'16']</option>";
>    echo "</select>";

This really is a faq: if you want to substitute anything other than a simple variable 
name into a double-quoted string, you MUST use curly braces {} to delimit it. So:

    echo "<option value=game1>${teams[$r.'1']}</option>";

is what you need.

(Note: I also treat variable names including underlines _ as being not simple, as I've 
had cases where PHP seems to parse these incorrectly -- for example, 
"...$long_name..." is treated as "...${long}_name...", not "...${long_name}...".)

If you have any doubts, include the {} -- even for simple variables, it does no harm 
to write, for example "...${var}...".

I do sometimes wonder whether the {} should be made mandatory in some future version, 
even for simple variables, to avoid exactly this kind of confusion.



Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to