by Jay » Wed Oct 09, 2002 2:16 pm
The main difference between using single quotes (') and double quotes(") is that single quotes will quote a string exacty:
print 'The variable value is $value'; will output The variable value is $value
Double quotes will parse the string for variables and replace them, therefore (assuming $value = 50) using double quotes for the same line will output The variable value is 50
You also can't use the same style quote within your string (otherwise the parser wouldn't know where your string ended). If you have to use the same quote, escape it with a backslash first so it's not taken literally (or use double quotes if you're using single - I personally find using double quotes far easier)
eg print 'That's Amazing' - Wrong
print 'That\'s Amazing' - Correct
print "That's Amazing" - Even better
You also cannot use an array variable within a string, unless you either access it directly in PHP (ie close the string, concatenate the variable and reopen the string) or enclose it within curly braces
eg - print "The value is $_SESSION['value']"; - Wrong
print "The value is {$_SESSION['value']}"; - OK
print "The value is ".$_SESSION['value']; - Much better