Results 1 to 4 of 4
May 14, 2011, 13:10 #1
Do I use single or double quotes for predefined variables like $_GET and $_COOKIE?
Is it best to use single quotes or double quotes for predefined variables like $_GET, $_POST, $_COOKIE and others?
The examples in the PHP Manual, for the section on predefined variables, use single quotes in some places and double quotes in other places.
PHP Manual Predefined Variables
Is there somewhere in the PHP Manual that tells where it is appropriate to use single quotes and where it is appropriate to use double quotes with the predefined variables?
May 14, 2011, 13:13 #2
doesn't matter - personal preferenceaaron-fisher.com - PHP articles and more
May 14, 2011, 13:40 #3
- Join Date
- Oct 2006
- France, deep rural.
- 17 Post(s)
- 1 Thread(s)
Just bear in mind;
$var = 'hello';
echo "Say $var"; //works - PHP expands the variable inside double quotes
echo "Say " . $var; // works
echo 'Say $var'; // does not work
echo 'Say ' . $var ; // works
$_POST['msg'] = "hello"; // $_POST is an array
echo "Say $_POST['msg']"; // does not work - does NOT expand the var in an array
echo "Say " . $_POST['msg']; // works
echo 'Say $_POST['msg']'; // does not work
echo 'Say ' . $_POST['msg'] ; // works
May 14, 2011, 15:17 #4
- Join Date
- May 2007
- Poole, UK
- 87 Post(s)
- 0 Thread(s)