Challenge - 5 Problems
PHP Hello World Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this PHP code?
Look at this PHP code. What will it print when run?
PHP
<?php echo "Hello World!"; ?>
Attempts:
2 left
💡 Hint
Remember PHP is case sensitive in strings and echo prints exactly what is inside quotes.
✗ Incorrect
The echo statement prints the exact string inside the quotes. So it prints Hello World! with capital H and W and a space.
❓ Predict Output
intermediateWhat error does this PHP code produce?
This PHP code is missing something. What error will it cause?
PHP
<?php echo "Hello World!" ?>
Attempts:
2 left
💡 Hint
Check if all statements end properly in PHP.
✗ Incorrect
PHP requires a semicolon at the end of statements. Missing it causes a parse error.
🧠 Conceptual
advancedWhich PHP tag is correct to start PHP code?
You want to write PHP code inside an HTML file. Which tag correctly starts PHP code?
Attempts:
2 left
💡 Hint
PHP code always starts with a special opening tag.
✗ Incorrect
The correct opening tag for PHP code is
❓ Predict Output
advancedWhat is the output of this PHP code?
What will this PHP code print?
PHP
<?php echo "Hello" . " " . "World!"; ?>
Attempts:
2 left
💡 Hint
The dot (.) operator joins strings in PHP.
✗ Incorrect
The dot operator concatenates strings. So it prints Hello, a space, then World! together.
❓ Predict Output
expertWhat is the output of this PHP code with variables?
Look at this PHP code. What will it print?
PHP
<?php $greeting = "Hello"; $target = "World!"; echo "$greeting $target"; ?>
Attempts:
2 left
💡 Hint
Variables inside double quotes are replaced by their values in PHP.
✗ Incorrect
PHP replaces variables inside double quotes with their values, so it prints Hello World! with a space.
Practice
1. What does the
echo statement do in a PHP program?easy
Solution
Step 1: Understand the role of
Theechoechostatement is used in PHP to display text or output on the screen.Step 2: Differentiate from other PHP parts
Starting and ending PHP code uses<?phpand?>, notecho. Variables are declared differently.Final Answer:
It prints text or output to the screen. -> Option AQuick Check:
echo = print output [OK]
Hint: Remember echo means print output on screen [OK]
Common Mistakes:
- Confusing echo with PHP start tag
- Thinking echo ends the program
- Mixing echo with variable declaration
2. Which of the following is the correct way to start a PHP script?
easy
Solution
Step 1: Identify the PHP opening tag
PHP scripts start with<?phpto tell the server to process PHP code.Step 2: Check other options
<php>and<?>are invalid tags.<script>is for JavaScript, not PHP.Final Answer:
<?php -> Option DQuick Check:
PHP starts with <?php [OK]
Hint: PHP always starts with <?php tag [OK]
Common Mistakes:
- Using <php> instead of <?php
- Confusing PHP tags with HTML or JavaScript tags
- Omitting the PHP start tag
3. What will be the output of this PHP code?
<?php echo "Hello World!"; ?>
medium
Solution
Step 1: Understand the echo statement
Theechocommand prints the string inside quotes to the screen exactly as it is.Step 2: Check the code syntax
The code uses correct PHP tags and syntax, so it will output the string "Hello World!".Final Answer:
Hello World! -> Option BQuick Check:
echo prints "Hello World!" [OK]
Hint: echo prints text inside quotes directly [OK]
Common Mistakes:
- Expecting code to print the echo statement itself
- Missing semicolon causing syntax error
- Not using correct PHP tags
4. Find the error in this PHP code:
<?php echo "Hello World!" ?>
medium
Solution
Step 1: Check the echo statement syntax
In PHP, each statement must end with a semicolon. The echo line is missing it.Step 2: Verify other parts
The PHP start tag and quotes are correct. The closing PHP tag is optional but present.Final Answer:
Missing semicolon after echo statement -> Option CQuick Check:
Statements need semicolon [OK]
Hint: Always end PHP statements with a semicolon [OK]
Common Mistakes:
- Forgetting semicolon at end of statement
- Confusing PHP tags with HTML tags
- Using wrong quotes like single without closing
5. You want to write a PHP program that prints "Hello World!" and then prints "Welcome to PHP." on the next line. Which code is correct?
hard
Solution
Step 1: Check syntax for multiple echo statements
Each echo must end with a semicolon.<?php echo "Hello World!"; echo "Welcome to PHP."; ?>
correctly uses two echo statements with semicolons.Step 2: Check other options for errors
<?php echo "Hello World!\nWelcome to PHP."; ?>
uses \n inside double quotes but PHP does not automatically print new lines in HTML output.<?php print "Hello World!" print "Welcome to PHP."; ?>
misses semicolon between print statements.<?php echo "Hello World!" echo "Welcome to PHP."; ?>
misses semicolon after first echo.Final Answer:
Two separate echo statements with semicolons -> Option AQuick Check:
Separate echo with semicolons for multiple lines [OK]
Hint: Use separate echo lines with semicolons for multiple outputs [OK]
Common Mistakes:
- Missing semicolons between statements
- Using print without semicolons
- Expecting \n to create new line in browser output
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
