Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a PHP script.
PHP
<?php ?>
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'echo' or 'start' instead of the PHP opening tag.
Forgetting to open the PHP tag.
✗ Incorrect
PHP scripts start with the
2fill in blank
mediumComplete the code to output text to the browser.
PHP
<?php echo [1]; ?>Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the text.
Using incomplete quotes.
✗ Incorrect
Text output in PHP must be inside quotes to be treated as a string.
3fill in blank
hardFix the error in the PHP code to correctly end the statement.
PHP
<?php echo 'Hello'[1] ?>
Attempts:
3 left
💡 Hint
Common Mistakes
Using a period or colon instead of a semicolon.
Forgetting to end the statement.
✗ Incorrect
Each PHP statement must end with a semicolon ; to separate it from the next.
4fill in blank
hardFill both blanks to create a PHP variable and assign a value.
PHP
<?php [1] = [2]; ?>
Attempts:
3 left
💡 Hint
Common Mistakes
Not using $ before variable name.
Assigning string without quotes.
✗ Incorrect
Variables in PHP start with $ and strings need quotes.
5fill in blank
hardFill all three blanks to create an associative array and access a value.
PHP
<?php $person = array([1] => [2]); echo $person[[3]]; ?>
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around keys or values.
Using wrong key to access array.
✗ Incorrect
Associative arrays use key => value pairs and keys are accessed with quotes.
Practice
1. What happens when a PHP file is requested by a browser?
easy
Solution
Step 1: Understand PHP execution location
PHP code runs on the server, not in the browser.Step 2: Identify what the browser receives
The server sends only the output (usually HTML) to the browser, not the PHP code itself.Final Answer:
The server runs the PHP code and sends the output to the browser -> Option CQuick Check:
PHP runs on server = A [OK]
Hint: Remember: PHP runs on server, browser gets output only [OK]
Common Mistakes:
- Thinking browser executes PHP code
- Expecting PHP code to be visible in browser source
- Confusing PHP with client-side languages like JavaScript
2. Which of the following is the correct way to start a PHP block in a file?
easy
Solution
Step 1: Recall PHP opening tags
The standard and recommended way to start PHP code is withStep 2: Check each option
uses which is correct. Others are invalid or incomplete tags.Final Answer:
-> Option AQuick Check:
Standard PHP tag = B [OK]
Hint: PHP code always starts with php [OK]
Common Mistakes:
- Using short tags like which may be disabled
- Confusing PHP tags with HTML or script tags
- Missing the 'php' keyword after
3. What will be the output of this PHP code when accessed via a browser?
<?php echo "Hello, " . "world!"; ?>
medium
Solution
Step 1: Understand echo statement
The echo command outputs the combined string "Hello, world!" to the browser.Step 2: Confirm string concatenation
The dot operator joins "Hello, " and "world!" correctly without errors.Final Answer:
Hello, world! -> Option DQuick Check:
echo concatenates strings = D [OK]
Hint: echo prints combined strings directly [OK]
Common Mistakes:
- Expecting PHP code to show in browser
- Confusing concatenation operator
- Thinking dot prints as text
4. Identify the error in this PHP code snippet:
<?php echo "Welcome to PHP!"
?>
medium
Solution
Step 1: Check syntax of echo statement
PHP statements must end with a semicolon ; to separate commands.Step 2: Locate missing semicolon
The echo line lacks a semicolon at the end, causing a syntax error.Final Answer:
Missing semicolon after echo statement -> Option BQuick Check:
Statements need ; = C [OK]
Hint: Always end PHP statements with a semicolon ; [OK]
Common Mistakes:
- Forgetting semicolon at line end
- Confusing PHP tags with HTML tags
- Assuming echo doesn't need semicolon
5. You want to create a PHP page that shows the current year dynamically. Which code snippet correctly does this?
<?php
// Options:
// A: echo date("Y");
// B: echo "date(Y)";
// C: echo date(Y, Y);
// D: echo "Y";
?>hard
Solution
Step 1: Understand PHP date function usage
The date function requires the format string in quotes to return the current year.Step 2: Evaluate each option
echo date("Y"); correctly calls date("Y") to output the year. echo "date(Y)"; prints the string literally. echo date(Y, Y); misses quotes causing undefined constants and wrong output (1970). echo "Y"; prints letter Y only.Final Answer:
echo date("Y"); -> Option AQuick Check:
Correct date format string = A [OK]
Hint: Use quotes around format in date() function [OK]
Common Mistakes:
- Omitting quotes around format string
- Printing function call as string
- Confusing output with literal text
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
