0

Possible Duplicate:
Difference between single quote and double quote string in php

In PHP, do both ( " ) and ( ' ) have the same effect? I'm new to PHP and I've been using them interchangeably. Can I?

Community
  • 1
  • 1
Amar H-V
  • 1,316
  • 3
  • 20
  • 33
  • I'll answer this with a similar question I posted myself... http://stackoverflow.com/questions/3016034/php-linefeeds-n-not-working – ggutenberg Nov 18 '11 at 06:00
  • And see also http://php.net/manual/language.types.string.php – mario Nov 18 '11 at 06:02
  • @mario this is not "also". this is **the only** place where one have to see. Unlike inadequate answers from amateurs, it is the only reliable source of information. – Your Common Sense Nov 18 '11 at 07:10

3 Answers3

3

Yes you can use single quoted or double quoted strings but they have some differences. Take a look at php string type.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

You you can use them interchangeably, however following are differences:

  • Inside double quotes, php is able to parse variables for example

    "Hello $name" // result: Hello [whatever stored in $name eg John]

  • Inside single quotes php is not able to parse variables:

    'Hello $name' // result: Hello $name

Since php does not parse variables from single quotes, using single quotes is slightly faster.

More Information:

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
0
$name = 'Amar';
echo "Hello, $name"; // outputs Hello, Amar
echo 'Hello, $name'; // outputs Hello, $name

Single quotes ( ' ) are faster by a very small margin since they don't need to scan strings for variables.

justin
  • 31
  • 4
  • What does it mean - "scan strings for variables"? how is it done? we take a string and scan it? why can't we do it while scanning the whole program? – Your Common Sense Nov 18 '11 at 07:01