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