Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Strange echo effect after reversing quotes

    I had:
    PHP Code:
    echo "{$content['size']}"
    ... and this echoed "Large", which is correct.

    I then switched the quotes around, so its now like this:
    PHP Code:
    echo '{$content["size']}; 
    The problem now is that instead of echoing "Large", it echo's "{$content["id"]} ".

    Why?!

  • #2
    Regular Coder
    Join Date
    Oct 2011
    Posts
    237
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by FlashDance View Post
    I had:
    PHP Code:
    echo "{$content['size']}"
    ... and this echoed "Large", which is correct.

    I then switched the quotes around, so its now like this:
    PHP Code:
    echo '{$content["size']}; 
    The problem now is that instead of echoing "Large", it echo's "{$content["id"]} ".

    Why?!
    you have ["size'] instead of ["size"] but that should throw up a error rather than that

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    If you only have a variable you won't need quotes at all.
    Try it like this:
    PHP Code:
    echo $content['size']; 

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    PHP doesn't parse the variables enclosed inside singles quotes, but it does for the double quotes. Is there any specific reason to interchange the quotes? Why don't you just use
    PHP Code:
    echo $content['size']; 
    or
    PHP Code:
    echo $content["size"]; 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    There is a tip in my signature about quotes. Take a look as it will explain this to you in greater detail.
    I can't really think of anything to write here now...

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    This fixed it:

    PHP Code:
    '.$content['size'].' 

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    You could also do it without quotes

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by Wanna View Post
    You could also do it without quotes
    Only inside double quotes.
    I can't really think of anything to write here now...

  • #9
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Quote Originally Posted by tangoforce View Post
    Only inside double quotes.
    I mean like this
    PHP Code:
    echo $content['size']; 

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Ah, I thought you meant

    PHP Code:
    '.$content[size].' 
    I can't really think of anything to write here now...


  •  

    Posting Permissions

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