Recall & Review
beginner
What is string interpolation in PHP when using double quotes?
String interpolation means PHP replaces variables inside double-quoted strings with their values automatically.
Click to reveal answer
beginner
How do you include a variable inside a double-quoted string in PHP?
Simply write the variable name inside the double quotes, like "$name". PHP will replace it with the variable's value.
Click to reveal answer
beginner
What happens if you use single quotes instead of double quotes for strings with variables in PHP?
Variables inside single quotes are treated as plain text, so no interpolation happens.
Click to reveal answer
intermediate
How can you include an array element inside a double-quoted string in PHP?
Use curly braces around the variable and key, like "{$array['key']}" to interpolate the value.
Click to reveal answer
intermediate
Why might you use curly braces {} around variables in double-quoted strings?
Curly braces help PHP understand where the variable name ends, especially when followed by letters or numbers.
Click to reveal answer
What will this PHP code output? <br>
$name = "Anna"; echo "Hello, $name!";
✗ Incorrect
PHP replaces $name with its value inside double quotes.
Which string syntax allows variable interpolation in PHP?
✗ Incorrect
Only double quotes allow variables to be replaced with their values.
How do you correctly interpolate an array element $arr['key'] inside a double-quoted string?
✗ Incorrect
Curly braces are needed to correctly parse array elements inside strings.
What will this output? <br>
$var = "day"; echo "Today is $var1";
✗ Incorrect
PHP tries to interpolate $var1, which is undefined, treating it as an empty string (with a notice), so the output is "Today is ".
Why use curly braces in "Hello, {$name}123"?
✗ Incorrect
Curly braces tell PHP where the variable name ends.
Explain how string interpolation works in PHP double-quoted strings.
Think about how PHP reads variables inside strings.
You got /3 concepts.
Describe how to include an array element inside a double-quoted string in PHP.
Remember how PHP parses complex variables inside strings.
You got /3 concepts.