0
0
PHPprogramming~10 mins

String interpolation in double quotes in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the variable inside double quotes using interpolation.

PHP
<?php
$name = "Alice";
echo "Hello, [1]!";
?>
Drag options to blanks, or click blank then click option'
Aname
B$name
C'$name'
D{name}
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the $ sign before the variable name.
Using single quotes which do not interpolate variables.
2fill in blank
medium

Complete the code to include the variable inside a sentence using double quotes and interpolation.

PHP
<?php
$age = 25;
echo "I am [1] years old.";
?>
Drag options to blanks, or click blank then click option'
A$age
B'$age'
Cage
D{age}
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes which do not interpolate variables.
Omitting the $ sign before the variable.
3fill in blank
hard

Fix the error in the code to correctly interpolate the variable inside double quotes.

PHP
<?php
$city = "Paris";
echo "Welcome to [1]!";
?>
Drag options to blanks, or click blank then click option'
A{city}
Bcity
C'$city'
D$city
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without $ inside double quotes.
Using single quotes which do not interpolate variables.
4fill in blank
hard

Fill both blanks to correctly interpolate the variable and add a suffix inside double quotes.

PHP
<?php
$score = 90;
echo "Your score is [1][2].";
?>
Drag options to blanks, or click blank then click option'
A$score
B%
C points
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the $ sign before the variable.
Using % instead of ' points' as suffix.
5fill in blank
hard

Fill all three blanks to create a sentence with two interpolated variables and a connector inside double quotes.

PHP
<?php
$firstName = "John";
$lastName = "Doe";
echo "My name is [1] [2] [3].";
?>
Drag options to blanks, or click blank then click option'
A$firstName
B$lastName
Cand
Dor
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without $ sign.
Using 'or' instead of 'and' as connector.