Page 1 of 1

$_POST["tags"] or $_POST['tags']?

Posted: Fri Aug 31, 2007 11:45 pm
by kkonline
What is the difference if i write

Code: Select all

$_POST["tags"]
and

Code: Select all

$_POST['tags']
?
which is better or which is preferred?

Posted: Sat Sep 01, 2007 2:25 am
by s.dot
In the way the code is executed, it doesn't make a difference.

But, how it differs:

PHP will try to interpret any variables and other characters when the code is between double quotes. So, use single quotes when you don't have any variables or other characters like new lines in your string. Using single quotes lets PHP know that it doesn't need to interpret anything, and is probably a bit faster.

Which is preferred? That's your own call...

Posted: Sat Sep 01, 2007 3:21 am
by kkonline
scottayy wrote:In the way the code is executed, it doesn't make a difference.

But, how it differs:

PHP will try to interpret any variables and other characters when the code is between double quotes. So, use single quotes when you don't have any variables or other characters like new lines in your string. Using single quotes lets PHP know that it doesn't need to interpret anything, and is probably a bit faster.

Which is preferred? That's your own call...
Ok ,
now if i am using

Code: Select all

$_POST['name']
then as name is a variable so i SHOULD use DOUBLE QUOTES ???

Posted: Sat Sep 01, 2007 3:31 am
by Chris Corbyn
kkonline wrote:
scottayy wrote:In the way the code is executed, it doesn't make a difference.

But, how it differs:

PHP will try to interpret any variables and other characters when the code is between double quotes. So, use single quotes when you don't have any variables or other characters like new lines in your string. Using single quotes lets PHP know that it doesn't need to interpret anything, and is probably a bit faster.

Which is preferred? That's your own call...
Ok ,
now if i am using

Code: Select all

$_POST['name']
then as name is a variable so i SHOULD use DOUBLE QUOTES ???
No, 'name' isn't variable, it's a static string. This would be variable:

Code: Select all

$name = "name";
echo $_POST[$name];

//or even

echo $_POST["foo_$name_bar"]; //foo_name_bar