SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <? print "{$stats['age']}"; ?> explanation

    Helping a friend with an application, and when returning results from an array from a query, instead of using the regular (to me anyway)

    PHP Code:
    <? echo $s['foo']; ?>
    he has used

    PHP Code:
    <? print "{$stats['age']}"?>
    and whilst both work (assuming I typed the code in correctly), I was wondering what the major differences are and why the {}s have been used..is it a print() specific thing or just user preference?

    Cheers

  2. #2
    SitePoint Addict
    Join Date
    Aug 2002
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    {} are only needed in case your need to use single quotes unescaped... for example in an SQL statement:

    PHP Code:
    $sql "INSERT INTO table values ('{$_POST['myvar']}')"
    otherwise, this would'nt work:
    PHP Code:
    $sql "INSERT INTO table values ('$_POST['myvar']')"

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you sometimes see it used to seperate code out when double quoted:

    print("<a href=\"index.php?id={$the_id}&name=phuckhead\"");

    Makes it a little easier to read too.
    isempty()

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •