PHP the difference between single and double quotes

PHP the difference between single and double quotes

Written by Tony Lea on Nov 15th, 2012 Views Report Post

I've been programming in PHP for nearly 10 years, and I would consider myself to be fairly competent with the language. It's funny that some of the simplest things that I would program in PHP I would just accept certain aspects instead of looking further into them. I am talking in particular about single and double quotes. You can use either of these to output lines of code to a browser. You can even use them interchangeably from line to line.

What's the difference between the two? Well, after going through a beginner PHP course I found out that using double quotes PHP will actually output and render PHP variables; whereas, a single quote will only print out the string without rendering PHP.

As an example, the following PHP code:

$name = 'World';
echo "Hello $name";

Will print out: Hello World

Whereas the following code:

$name = 'World';
echo 'Hello $name';

Will print out: Hello $name

It's funny that it took me that long to figure that out. I guess it was just one of those things I didn't pay attention to. Well, now I know :P

Comments (0)