RE: [PHP] Parse error: parse error, expecting `']'' in

From: Date: Thu, 02 Dec 2004 16:49:14 +0000
Subject: RE: [PHP] Parse error: parse error, expecting `']'' in
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-203365@lists.php.net to get a copy of this message
>> 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. And for all consistencies within your script it can be helpful if you use $_POST[cityname] as a define worded array and $_POST['cityname'] as a string keyed array and keep that seperated if ever someone else were to look through your code. As the manuel shows: // Works but note that this works differently outside string-quotes echo "A banana is $fruits[banana]."; // Works echo "A banana is " . $fruits['banana'] . "."; Consistency can go a long way. :) You are right about the complex syntax. -- --Matthew Sims --<http://killermookie.org>

« previous php.general (#203365) next »