SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member achim_g's Avatar
    Join Date
    Nov 2003
    Location
    Cologne
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what syntax are the curly brackets in echo

    Hello,

    what syntax are the curly brackets in

    echo "value: {$foo['bar']}";


    I know it's for "escaping" the single quotation marks.

    Thanks, Achim

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is the correct syntax
    Didn't it work when you tried it?

  3. #3
    SitePoint Member achim_g's Avatar
    Join Date
    Nov 2003
    Location
    Cologne
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by markl999
    That is the correct syntax
    Didn't it work when you tried it?
    yes, it worked. What element of syntax is it? Usually you use curly brackets starting or ending a block.

    Achim

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's just so it parses correctly, without the {}'s, using that syntax, you'll get a parse error - Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    I tend to just use:
    echo 'value: '.$foo['bar'];
    rather than put 'complex' vars inside a string.

  5. #5
    SitePoint Member achim_g's Avatar
    Join Date
    Nov 2003
    Location
    Cologne
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just wondered that the {}'s aren't printed and that the parser recognises them within the echo.

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe http://php.net/manual/en/language.types.string.php can explain it better than i can
    Search down that page for 'Complex (curly) syntax'

  7. #7
    SitePoint Member achim_g's Avatar
    Join Date
    Nov 2003
    Location
    Cologne
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ohio
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a question... and this seems like a good place to ask it.

    Can I use those to do something likeÖ

    PHP Code:
    echo("value: {$lang['admin']['admin']}"); 
    Basically I ask since I canít seem to get PHP to recognize 2D arrays in strings and I havenít yet tried the '{}' thing.

  9. #9
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you can.
    Though i'd still go with:
    echo 'value: '.$lang['admin']['admin'];


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •