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!
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
Why don't we use from the first ("") double quotes when we use echo instead of changing it every time we use a variable?
double quotes works if we want to echo a string. Why we use first single quotes and than changing it if we a have a variable to double quotes?
Casey Ydenberg15,622 Points
Probably the answer is that single quotes are a little faster for the PHP parser - it doesn't have to look through the string to decide if there are any variables inside of it.
IMO it's also a little more readable - a human doesn't have to decide if there are variables that they will have to worry about later; they know it's just a simple string that doesn't depend on any other code.
Benjamin Larson34,055 Points
Reading the PHP manual can seem a bit cryptic if you are first learning the language, but it does have great explanations for the different types of syntax that can be used for specifying strings. There are actually 4 ways to specify strings (as of PHP 5.3.0):
- heredoc syntax
- nowdoc syntax
There are pros and cons to using each. Check it out at the PHP manual: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single