0
0
PHPprogramming~10 mins

String concatenation operator 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 concatenate two strings using the correct operator.

PHP
<?php
$greeting = "Hello" [1] " World!";
echo $greeting;
?>
Drag options to blanks, or click blank then click option'
A+
B&&
C&
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of . for string concatenation.
Using && which is a logical operator.
2fill in blank
medium

Complete the code to join the variables $first and $last into $fullName.

PHP
<?php
$first = "John";
$last = "Doe";
$fullName = $first [1] $last;
echo $fullName;
?>
Drag options to blanks, or click blank then click option'
A,
B+
C.
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which causes errors with strings.
Using commas which do not concatenate strings.
3fill in blank
hard

Fix the error in concatenating $a and $b with a space between them.

PHP
<?php
$a = "Good";
$b = "Morning";
$result = $a [1] " " [2] $b;
echo $result;
?>
Drag options to blanks, or click blank then click option'
A.
B+
C,
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which causes errors.
Using commas which do not concatenate strings.
4fill in blank
hard

Fill both blanks to concatenate $city and $country with a comma and space between.

PHP
<?php
$city = "Paris";
$country = "France";
$location = $city[1] ", " [2] $country;
echo $location;
?>
Drag options to blanks, or click blank then click option'
A.
B+
C,
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which is for numbers.
Using commas which do not concatenate strings.
5fill in blank
hard

Fill all three blanks to build a greeting with $name and $day.

PHP
<?php
$name = "Alice";
$day = "Monday";
$message = "Hello, "[1] $name [2] "! Today is " [3] $day;
echo $message;
?>
Drag options to blanks, or click blank then click option'
A+
B.
C,
D&&
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which causes errors with strings.
Using commas or && which do not concatenate strings.