You are here: Re: Just Learning PHP « PHP Language « IT news, forums, messages
Re: Just Learning PHP

Posted by Ian Hobson on 09/06/07 22:24

macca wrote:
>> <?php
>> $fred = 'Click here to visit my site;
>> echo "<a href='www.mydomain.com'>$fred</a>";
>> ?>
>
>
>
> Shouldnt that be :
>
> echo "<a href='www.mydomain.com'>{$fred}</a>";
>
>
> Seriously, What's the deal with using brackets inside am
> interpolation?
>
If by "Whats the deal?" you want to know why they are used....

Both versions will work inside a double quotes string (or here doc).
Single quoted strings are not expanded.

If the variable reference is compound (e.g. $a[4], $this->var) then
braces are necessary.

[echo "<a href='www.mydomain.com'>$fred</a>";] is essentially the same
speed as [echo "<a href='www.mydomain.com'>{$fred}</a>";] while [echo
"<a href='www.mydomain.com'>".$fred."</a>"; ] is slower.

Leaving braces out when they are not necessary makes the code clearer.

If you mean "Why shouldn't I do it?"...

Its your code. <shrug>

Regards

Ian

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация