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 #169554 is a reply to message #169552] Fri, 17 September 2010 18:06 Go to previous messageGo to previous message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma:
Member
On Sep 17, 1:44 pm, bruceaj <bruc...@bellsouth.net> wrote:
> On Sep 16, 11:47 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>
>
>> 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.
>> jstuck...@attglobal.net
>> ==================
>
> Sorry I didn't explain the problem more clearly. Yes, this what I was
> asking about curly brackets. I'm aware of curly bracket when wrapping
> code but I can't seem to find the explanation when using them to wrap
> array elements. That is where I have seen them used in code examples,
> likc "SELECT a FROM b WHERE t={$_GET['x']}";

This, I hope you realize, is a terrible example because it
demonstrates a tried a true method of allowing SQL injection.
[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 16:42:02 GMT 2024

Total time taken to generate the page: 0.04700 seconds