Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Single vs Double Quotes (I must have missed it in the tracks)

Below is an excerpt from THE JOY OF php PROGRAMMING.

In PHP, it matters if you create a string surrounded by single quotes or double quotes. If you enclose a string within single quotes PHP will return that exact string. When you enclose a string in double quotes, any variables within the string will be substituted for their values.

<?php

echo 'this is a string';
echo "<br>this is a string";
// both output the same thing
$icecream = "chocolate";
echo '<br>I like $icecream icecream'; // prints I like $icecream icecream
echo "<br>I like $icecream icecream"; // prints I like chocolate icecream

?>

3 Answers

Jeff Busch - Good info.

I think about it like this:

double quotes are for anything that needs evaluation single quotes are for everything else

echo 'hey there fella!';

echo "hey there $name!";

if you want to get even more crafty how about evaluation inside of a string, or escape sequences.

This is where the docs come into play.

http://www.php.net/manual/en/language.types.string.php

php can handle some awesome stuff when it comes to strings...

indeed

Alan Mattan贸
Alan Mattan贸
12,329 Points

" vs ' Can you expand the concept of, "evaluation", please.

Is apply to this ?

$_GET['value']; vs $_GET["value"];

or

header('Location: confirmed.php'); vr header("Location: confirmed.php");

Are the same?