[thelist] MySQL/PHP Associative Array Insert

R.Livsey R.Livsey at cache-22.co.uk
Sat Feb 1 13:52:12 CST 2003


nicky wrote:

>> <tip type="php - cleaner code">
>>
>> If you are using complex variables such as associative arrays in a
>> string you can enclose them with curly braces in order to get PHP to
>> parse them.
>> ie:
>> $str = "here are some values of an associative array:
>> {$assocArr['one']}, {$assocArr['foo']}, {$assocArr['bar']}.";
>> much nicer (IMO) than
>> $str = "here are some values of an associative array:
>> ".$assocArr['one'].", ".{$assocArr['foo']}.", ".{$assocArr['bar']}.".";
>>
>> </tip>
>
>
> It's even better to not use double quotes (because php will note
> evaluate what is inside simple quote, usefull for very long string) like
> this :
>
> $str='here are some values of an associative array:'.$assocArr['one'].',
> '.{$assocArr['foo']}.', '.{$assocArr['bar']}.'.';
> --
> [ nicky ] [ nicky at deveha.com ] [ icq : 19223680 ]
>
Agreed, but my main point was that if using {} you don't need to come
out of the quotes because everything will be parsed.

--
R.Livsey
Incutio Web Developer
[ PHP | Perl | Java | C# ]
www.cache-22.co.uk
www.incutio.com





More information about the thelist mailing list