Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$name = 'Anna';
echo 'Hi, $name!', ' ', "Hi, $name!", ' ', "{$name}s", "\n";Hi, $name! Hi, Anna! Annas
- Expecting
'Hi, $name!'to showAnna: a single-quoted string is printed as typed, so$namestays the five characters$name. - Expecting the braces of
{$name}sin the output: they only tell PHP where the variable name ends, and{$name}is replaced by the value as a whole.
- What would
"$names"print in this program, and why? - How do you print a dollar sign followed by the word
nameinside double quotes?