[thelist] PHP - need clarification of quotes in array names.

Afonso Fernandez Nogueira afonso at writeme.com
Wed Feb 6 05:35:00 CST 2002


> How then do I echo $foo['bar'] as part of a string? if I have:
> $foo['bar'] = "hello";
> echo "$foo['bar'] world";
> This gives an error.
> If I have
> $foo['bar'] = "hello";
> echo "$foo[bar] world";
> This works, but is it wrong?

echo "$foo[bar] world"
is okay. It's not, of course, the general "right" way to refer to the array index, but that rule changes for string interpolation.

cheers,
fonso




More information about the thelist mailing list