totally newb question



Is there something I can read on where and when to use correctly the characters " ' and ; I find myself going back and fourth with these somethimes not sure what the rules are.

$_SESSION['sessionuser'] = "$row[userfield]";

and similar
I usually always use ' on everything to avoid confusion. When you use " it allows you to parse variables within the string and also escape special characters i.e. "\n" will put a return in your source.


$foo = 'bar';
echo "$foo";

//output: bar

will print the variable value of $foo cause it parses it.

$foo = 'bar';
evho '$foo';

//output $foo

using single quotes does recognize $foo as a variable but as literal text.

with arrays it's a little different.

$foo['bar'] is the same as $foo["bar"] because there is no variable withing the quotes on either of them but they are different from $foo[bar] without the quotes. php thinks bar is a constant because it has no quotes around it.

"$foo[bar]" would be the same as $foo["bar"] but not '$foo[bar]'

for more info see