Challenge - 5 Problems
PHP Echo vs Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output difference between echo and print
What is the output of this PHP code snippet?
PHP
<?php $result = print('Hello'); echo $result; ?>
Attempts:
2 left
💡 Hint
Remember that print returns a value after outputting the string.
✗ Incorrect
The print statement outputs 'Hello' and returns 1, which is then echoed, resulting in 'Hello1'.
❓ Predict Output
intermediate2:00remaining
Echo with multiple parameters
What will this PHP code output?
PHP
<?php echo 'Hi', ' ', 'there!'; ?>
Attempts:
2 left
💡 Hint
Echo can take multiple parameters separated by commas.
✗ Incorrect
Echo outputs all parameters concatenated without spaces unless explicitly added. Here, a space is added as the second parameter.
❓ Predict Output
advanced2: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; ?>
Attempts:
2 left
💡 Hint
Echo is a language construct, not a function, and does not return a value.
✗ Incorrect
Echo cannot be used in an expression or assigned to a variable, so this code causes a syntax error.
❓ Predict Output
advanced2:00remaining
Print with parentheses
What is the output of this PHP code?
PHP
<?php print('Hello'); print ('World'); ?>
Attempts:
2 left
💡 Hint
Print can be used with or without parentheses.
✗ Incorrect
Print outputs the strings exactly as given. No spaces or newlines are added automatically.
❓ Predict Output
expert2:00remaining
Combining echo and print in expressions
What is the output of this PHP code?
PHP
<?php $sum = print('A') + print('B'); echo $sum; ?>
Attempts:
2 left
💡 Hint
Print outputs the string and returns 1, so adding two prints returns 2.
✗ Incorrect
Print outputs 'A' and 'B' then returns 1 each. Adding them gives 2, which is echoed after the letters.