Thursday 23 January 2014

Difference Between Single And Double Quotes in PHP


Difference Between Single And Double Quotes in PHP In PHP you can specify the strings by using single and double quotes. There are other methods (heredoc and nowdoc (since PHP 5.3.0)) are also used but first two are used mostly.
It is important to know the difference between using single quotes and double quotes. In this post we will see the difference between them and which should be used when


Single Quotes:
When string is specified in single quotes PHP will not evaluate it or interpret escape characters except single quote with backslash (‘) and backslash(\) which has to be escaped.
  <?php
   $name = 'srinu chilukuri';
   $member = 'This is $name';
   echo $member;
     ?>
If echo $member variable it will print the result as it is without interpreted.

output: This is $name

Double Quotes:
In double quoted strings other escape sequences are interpreted as well any variable will be replaced by their value.
  <?php
   $name = 'srinu chilukuri';
   $member = "This is $name";
   echo $member;
     ?>
output: This is srinu chilukuri