Challenge - 5 Problems
Output Mastery in PHP
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of echo vs print
What is the output of the following PHP code?
PHP
<?php echo 'Hello'; print ' World!'; ?>
Attempts:
2 left
💡 Hint
Both echo and print output strings directly.
✗ Incorrect
Both echo and print output their strings directly without adding spaces or newlines. So the output is 'Hello World!'.
🧠 Conceptual
intermediate2:00remaining
Why use output buffering?
Why is output buffering useful in PHP?
Attempts:
2 left
💡 Hint
Think about controlling when output is sent.
✗ Incorrect
Output buffering lets you collect output in memory first, so you can modify or delay sending it to the browser.
🔧 Debug
advanced2:00remaining
Why does this code produce no output?
What is the reason this PHP code produces no output?
PHP
<?php ob_start(); echo 'Test'; // missing ob_end_flush(); ?>
Attempts:
2 left
💡 Hint
Check what happens to buffered output if not flushed.
✗ Incorrect
The output is stored in the buffer but never sent because ob_end_flush() or ob_flush() is not called.
📝 Syntax
advanced2:00remaining
Identify the syntax error in output code
Which option contains a syntax error in PHP output code?
PHP
<?php print('Hello World!'); echo 'Goodbye'; ?>
Attempts:
2 left
💡 Hint
Check semicolon placement carefully.
✗ Incorrect
Option A has a semicolon after the PHP closing tag, which is invalid syntax.
🚀 Application
expert2:00remaining
How many items are in the output array?
What is the number of elements in the array returned by this PHP code?
PHP
<?php ob_start(); echo 'A'; echo 'B'; $output = ob_get_contents(); ob_end_clean(); $result = str_split($output); return $result; ?>
Attempts:
2 left
💡 Hint
Count characters echoed before capturing output.
✗ Incorrect
The output buffer contains 'AB', so str_split creates an array with 2 elements: 'A' and 'B'.