RE: [PHP] Parse error: parse error, expecting `']'' in
| From: | Ford, Mike | Date: | Thu, 02 Dec 2004 17:11:35 +0000 |
| Subject: | RE: [PHP] Parse error: parse error, expecting `']'' in | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-203366@lists.php.net to get a copy of this message | ||
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
On 02 December 2004 16:49, Matthew Sims wrote:
> > > So when using arrays with string keys within strings you need to
> > > concatenate it.
> > >
> > > $var = "I live in the city of ". $_POST['cityname'];
> >
> > No, you do not *need* to -- it is one option, certainly, but there
> > is no necessity about it.
> >
> > Within double-quoted strings, it is perfectly acceptable to use
> > unquoted array keys:
> >
> > $var = "I live in the city of $_POST[cityname]";
>
> True and that is perfectly fine though PHP will check to see
> if cityname
> is a defined word first.
No it will not -- not in a double-quoted string (if by "defined word" you
mean constant).
Outside of a double-quoted string, yes it will.
>
> As the manuel shows:
>
> // Works but note that this works differently outside string-quotes
> echo "A banana is $fruits[banana].";
Yes -- *works*, as in always works, because no constant lookup is done when
interpolating within a double-quoted string.
> Consistency can go a long way. :)
Oh, I agree with you there, which is why I personally always use the
"...{$arr['index']} ..." syntax.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211