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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> 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>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux