There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Hi, so I took PHP a while back, but a lot of it never really stuck.
I remember something about “$variable = value” versus “$variable == value” and that you should never, never, never confuse the two…but I can’t remember why.
What is the reason for using echo twice? Wouldn’t it be easier and use less code to concatenate it together?
Instead of this:
<?php
// Write your code below:
$name = "Tom Smith";
$language = "Russian";
echo "My name is " . $name . " and I have an awesome dog named Mojo" . ".";
echo "\nMojo speaks " . $language . ".";
Do this:
<?php
// Write your code below:
$name = "Tom Smith";
$language = "Russian";
echo "My name is " . $name . " and I have an awesome dog named Mojo" . "." . "\nMojo speaks " . $language . ".";
Good question. Either approach is valid, but you are right to look for ways to simplify the code and reduce repetition.
Something to know about double quoted strings in PHP… They support interpolation, so concatenation is not necessary. The same cannot be said for single quoted strings. They do not support interpolation.
echo "My name is $name and I have an awesome dog named Mojo.\nMojo speaks $language.";
On a technical note, echo is rather a complex process for the server to handle and can use a lot of resources. Composing an entire document into one large string is permitted. We can output it (write it to the request document) with a single echo statement.