0
0
PHPprogramming~20 mins

Echo vs print behavior in PHP - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Echo vs Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output difference between echo and print
What is the output of this PHP code snippet?
PHP
<?php
$result = print('Hello');
echo $result;
?>
AError
BHello1
C1Hello
DHello
Attempts:
2 left
💡 Hint
Remember that print returns a value after outputting the string.
Predict Output
intermediate
2:00remaining
Echo with multiple parameters
What will this PHP code output?
PHP
<?php
echo 'Hi', ' ', 'there!';
?>
AHi there!
BHi, there!
CError
DHi
Attempts:
2 left
💡 Hint
Echo can take multiple parameters separated by commas.
Predict Output
advanced
2:00remaining
Return value of echo
What happens when you try to assign the result of echo to a variable?
PHP
<?php
$value = echo 'Test';
echo $value;
?>
ASyntax error
BTest1
CTest
D0
Attempts:
2 left
💡 Hint
Echo is a language construct, not a function, and does not return a value.
Predict Output
advanced
2:00remaining
Print with parentheses
What is the output of this PHP code?
PHP
<?php
print('Hello');
print ('World');
?>
A
Hello
World
BHello World
CHelloWorld
DError
Attempts:
2 left
💡 Hint
Print can be used with or without parentheses.
Predict Output
expert
2:00remaining
Combining echo and print in expressions
What is the output of this PHP code?
PHP
<?php
$sum = print('A') + print('B');
echo $sum;
?>
AError
BAB
C2
DAB2
Attempts:
2 left
💡 Hint
Print outputs the string and returns 1, so adding two prints returns 2.