0
0
PHPprogramming~20 mins

String concatenation operator in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP String Concatenation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this PHP code using concatenation?
Consider the following PHP code snippet. What will it print?
PHP
<?php
$a = "Hello";
$b = "World";
echo $a . " " . $b . "!";
?>
AHello World!
BHelloWorld!
CHello World
DHello.World!
Attempts:
2 left
💡 Hint
Remember the dot (.) operator joins strings exactly as written.
Predict Output
intermediate
2:00remaining
What does this PHP code output with mixed concatenation and addition?
Look at this PHP code. What will it output?
PHP
<?php
$x = 5;
$y = "10";
echo $x + $y . " apples";
?>
A510 apples
B15 apples
C5 apples
DTypeError
Attempts:
2 left
💡 Hint
PHP converts strings to numbers when using + operator.
🔧 Debug
advanced
2:00remaining
Which option causes a syntax error in PHP string concatenation?
Identify which code snippet will cause a syntax error when run.
A<?php echo "Hello" .+ "World"; ?>
B<?php echo "Hello" + "World"; ?>
C<?php echo "Hello" . " " . "World"; ?>
D<?php echo "Hello" . "World"; ?>
Attempts:
2 left
💡 Hint
Check the operator symbols carefully.
Predict Output
advanced
2:00remaining
What is the output of this PHP code with concatenation assignment?
What will this PHP code print?
PHP
<?php
$str = "Good";
$str .= " Morning";
$str .= "!";
echo $str;
?>
AGood . Morning!
BGoodMorning!
CGood Morning
DGood Morning!
Attempts:
2 left
💡 Hint
The '.=' operator adds to the existing string.
🧠 Conceptual
expert
2:00remaining
How many items are in the resulting array after this PHP code runs?
What is the count of elements in the array after this code executes?
PHP
<?php
$arr = [];
$arr['a'] = 'Hello';
$arr['b'] = 'World';
$arr['a'] .= ' PHP';
?>
A1
B3
C2
D0
Attempts:
2 left
💡 Hint
Appending to an existing key does not add new elements.