FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » When do I use {}?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: When do I use {}? [message #169530 is a reply to message #169528] Fri, 17 September 2010 03:47 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 9/16/2010 10:13 PM, bruceaj wrote:
> I have code samples where some variables are wrapped in {} (curly
> brackets.) My problem is that I can find anything in the documentation
> when they can be uses.
>
> Can someone tell me or point me to some documentation??
>
> Thanks...
>
> Bruce

You use them when you want to evaluate non-simple variables (i.e. array
elements) in a double-quoted string, such as:

$a = 'World"; // init variable
$b = array('Hello', 'World');

echo "Hello $a"; // Works - $a is a simple variable
echo "Hello {$a}"; // Also works - and may be clearer

echo "Hello $b[1]"; // Does NOT work - $b is an array
echo "Hello {$b[1]}"; // This one works
echo "{$b[0]} {$b[1]}"; // Also works

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: OOP, classes and databases
Next Topic: @sessionstart()
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 17:07:35 GMT 2024

Total time taken to generate the page: 0.04870 seconds