Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of . for string concatenation.
Using && which is a logical operator.
✗ Incorrect
In PHP, the dot . operator is used to join (concatenate) strings.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which causes errors with strings.
Using commas which do not concatenate strings.
✗ Incorrect
The dot . operator joins two strings stored in variables.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which causes errors.
Using commas which do not concatenate strings.
✗ Incorrect
Use the dot . operator to concatenate multiple strings and variables.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which is for numbers.
Using commas which do not concatenate strings.
✗ Incorrect
Use the dot . operator to join strings and literals.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + which causes errors with strings.
Using commas or && which do not concatenate strings.
✗ Incorrect
Use the dot . operator to join all parts of the greeting string.