Difference between Single quote & Double quote used in PHP ?


Single quotes will escape anything other than a backslash followed by either a single quote or another backslash literally.

Double quotes, however, will evaluate variable values and function calls before producing the final output, and include them within it. This is called (at least in Perl’s context), “interpolation”. So, given:

$var = ‘123’;
echo ‘$var’; // outputs $var
echo “$var”; // outputs 123

Single quotes reads the variable as a string but the Double quote reads the variable as a variable and returns the value for that variable.

For more information, take a look at the official documentation: http://php.net/manual/en/language.types.string.php

Advertisements