Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30129
    thisishard
    Member

    Could someone please tell me when i should you single quotes and when to use double quotes. At the moments my code seems to vary depending on what my hands hits at the time.

    #80739
    Chris Coyier
    Keymaster

    In HTML and JavaScript it doesn’t matter, so long as your opening ones match your closing ones, and if you need to use one or the other inside, you alternate.

    In PHP, using double quotes allows you to use $variables inside the quotes, where single quotes do not.

    #80718
    Rob MacKay
    Participant

    Yea you just have to remember when using “” and vars that you don’t need to open array keys in ” – for example….

    echo "this is a string $array[key]"; 

    will work, as does

    echo 'this is a string ' . $array;

    But what is really good to use is curly brackets { }

    echo "this is a string {$array}";

    Then you don’t have to worry and you can use multidimensional key access with no headaches :D

    #80660
    Luminated
    Member

    “multidimensional key access”

    Thank you neo! ;)

    #80661
    Rob MacKay
    Participant

    No problem – now I must away! Mr Smith is gathering!

    #80657
    thisishard
    Member

    Thanks People.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.