0
0
PHPprogramming~20 mins

String type (single vs double quotes) in PHP - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Mastery in PHP
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of variable interpolation in strings
What is the output of the following PHP code?
PHP
<?php
$name = "Alice";
echo 'Hello, $name!';
?>
AHello, Alice!
BSyntax error
CHello, !
DHello, $name!
Attempts:
2 left
💡 Hint
Remember how single quotes treat variables inside strings in PHP.
Predict Output
intermediate
2:00remaining
Escape sequences in single vs double quotes
What will this PHP code output?
PHP
<?php
echo "Line1\nLine2";
echo '\nLine3';
?>
A
Line1
Line2\nLine3
BLine1\nLine2\nLine3
C
Line1
Line2
Line3
D
Line1\nLine2
Line3
Attempts:
2 left
💡 Hint
Check how escape sequences like \n behave in single and double quotes.
🔧 Debug
advanced
2:00remaining
Why does this string concatenation fail?
Consider this PHP code snippet. Why does it cause an error?
PHP
<?php
$name = "Bob";
echo 'Hello, ' . $name . '!';
echo 'He said, "Hi!"';
echo 'It\'s sunny';
?>
ANo error; all lines run fine.
BThe third echo causes a syntax error because the single quote inside is not escaped properly.
CThe first echo causes a syntax error because concatenation uses wrong operator.
DThe second echo causes a syntax error because double quotes inside single quotes are not allowed.
Attempts:
2 left
💡 Hint
Look carefully at how quotes inside strings are escaped.
Predict Output
advanced
2:00remaining
Output of complex variable interpolation
What is the output of this PHP code?
PHP
<?php
$fruit = "apple";
echo "I have an {$fruit}s.";
?>
AI have an apple s.
BI have an apples.
CI have an {$fruit}s.
DI have an apple.
Attempts:
2 left
💡 Hint
Look at how curly braces help with variable interpolation.
🧠 Conceptual
expert
2:00remaining
Difference in performance between single and double quotes
Which statement about single and double quoted strings in PHP is TRUE?
ADouble quoted strings are faster because they allow variable interpolation.
BThere is no performance difference between single and double quoted strings in PHP.
CSingle quoted strings are always faster because PHP does not parse variables or escape sequences inside them.
DSingle quoted strings cause syntax errors if they contain variables.
Attempts:
2 left
💡 Hint
Think about what PHP does internally when parsing strings.