From the course: Learning PHP

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Single vs. double quotes

Single vs. double quotes - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

Single vs. double quotes

- [Instructor] So you can use single or double quotes for strings but what's the difference? Let's take a look. The main difference between single and double quotes is any string in double quotes will be processed by PHP before it's outputted. That means, for example, any variables in strings with double quotes will become their literal value. Let's take a look at an example here where on the left side of the screen, I have my code and on the right side of the screen, I have the result in the browser. I'll type my opening php tag. And then I will create a variable called name. So we'll say name gets Joe. And I'll put Joe in single quotes. Then we'll say echo double quote Hello, comma space name. Remember, PHP prints exactly as we type within the quotes, so we need to add any punctuation and spaces and things like that. Then we'll add our semicolon. We'll save this and we'll fresh the page. You could see it says…

Contents