0
0
PHPprogramming~20 mins

Comments in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PHP Comments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of PHP code with comments
What is the output of this PHP code snippet?
PHP
<?php
// This is a single-line comment
echo "Hello"; /* This is a
multi-line comment */
echo " World!";
?>
A
Hello
 World!
BHello World!
C
Hello/* This is a
multi-line comment */ World!
DSyntax Error
Attempts:
2 left
💡 Hint
Remember that comments are ignored by PHP and do not affect output.
🧠 Conceptual
intermediate
1:30remaining
Purpose of comments in PHP
What is the main purpose of comments in PHP code?
ATo explain the code to humans without affecting execution
BTo make the code run faster
CTo store data inside the code
DTo create variables
Attempts:
2 left
💡 Hint
Think about what comments do when the PHP engine runs the code.
Predict Output
advanced
2:00remaining
Output with nested comment-like syntax
What will this PHP code output?
PHP
<?php
/* Start comment
// This is not a comment
echo "Hello";
End comment */
echo "World!";
?>
AHello
BHelloWorld!
CWorld!
DSyntax Error
Attempts:
2 left
💡 Hint
Remember that everything inside /* */ is ignored, even if it looks like code.
📝 Syntax
advanced
1:30remaining
Identify syntax error with comments
Which option will cause a syntax error in PHP?
A<?php /* Unclosed multi-line comment
B<?php // Comment without closing tag
C<?php echo "Hello"; // Proper comment
D
&lt;?php # Single-line comment
 echo "Hi"; ?&gt;
Attempts:
2 left
💡 Hint
Check if all multi-line comments are properly closed.
🚀 Application
expert
2:30remaining
Count lines of code excluding comments
Given this PHP code, how many lines of actual code (not comments or blank lines) does it contain?
PHP
<?php
// Initialize
$a = 5;
/* Multi-line
comment here */
$b = 10;

# Another comment
$c = $a + $b;
echo $c;
?>
A3
B5
C6
D4
Attempts:
2 left
💡 Hint
Count only lines with actual PHP code, ignore comments and empty lines.