Bird
Raised Fist0
PHPprogramming~10 mins

What is PHP - Interactive Quiz & Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print "Hello, World!" in PHP.

PHP
<?php
echo [1];
?>
Drag options to blanks, or click blank then click option'
A"Hello, World!"
BHello, World!
C'Hello World'
DHello World
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the text causes errors.
Using unquoted text is treated as a constant, causing errors.
2fill in blank
medium

Complete the code to declare a variable named $name with the value "Alice".

PHP
<?php
[1] = "Alice";
?>
Drag options to blanks, or click blank then click option'
Aname
B$name
Cvar name
Dlet name
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ sign before variable names.
Using JavaScript style variable declarations like var or let.
3fill in blank
hard

Fix the error in the PHP code to correctly concatenate two strings.

PHP
<?php
$greeting = "Hello" [1] " World!";
echo $greeting;
?>
Drag options to blanks, or click blank then click option'
A+
B&&
C&
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of . for string concatenation.
Using logical operators like & or && by mistake.
4fill in blank
hard

Fill both blanks to create an associative array with keys "name" and "age".

PHP
<?php
$person = array([1] => "Bob", [2] => 30);
?>
Drag options to blanks, or click blank then click option'
A"name"
B"age"
Cname
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys which are treated as constants.
Mixing keys with and without quotes.
5fill in blank
hard

Fill all three blanks to write a PHP function named greet that takes a $name and returns a greeting string.

PHP
<?php
function [1]([2]) {
    return "Hello, " . [3] . "!";
}
?>
Drag options to blanks, or click blank then click option'
Agreet
B$name
Dhello
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without $ inside the function.
Naming the function with a $ sign.
Using different names for parameter and inside variable.

Practice

(1/5)
1. What is PHP mainly used for?
easy
A. Designing static images
B. Editing videos
C. Writing desktop applications
D. Creating dynamic and interactive websites

Solution

  1. Step 1: Understand PHP's purpose

    PHP is a language designed to create dynamic content on websites, making them interactive.
  2. Step 2: Compare options

    Only Creating dynamic and interactive websites matches PHP's main use; others relate to different fields.
  3. Final Answer:

    Creating dynamic and interactive websites -> Option D
  4. Quick Check:

    PHP = Dynamic websites [OK]
Hint: PHP is for web interaction, not static or media tasks [OK]
Common Mistakes:
  • Thinking PHP edits images or videos
  • Confusing PHP with desktop app languages
2. Which of these is the correct way to start PHP code in a file?
easy
A. <?php
B. <script>
C. <php>
D. <?html>

Solution

  1. Step 1: Recall PHP opening tags

    PHP code starts with <?php to tell the server to run PHP.
  2. Step 2: Check other tags

    <script> is for JavaScript, <php> and <?html> are invalid.
  3. Final Answer:

    <?php -> Option A
  4. Quick Check:

    PHP code starts with <?php [OK]
Hint: PHP always starts with <?php tag [OK]
Common Mistakes:
  • Using <script> instead of PHP tags
  • Writing <php> which is not valid
3. What will this PHP code output?
<?php
 echo "Hello, World!";
?>
medium
A. Syntax Error
B. Hello, World!
C. <?php echo "Hello, World!"; ?>
D. Nothing

Solution

  1. Step 1: Understand echo statement

    The echo command prints the text inside quotes to the browser.
  2. Step 2: Check code correctness

    The code is correct PHP syntax and will output the string exactly.
  3. Final Answer:

    Hello, World! -> Option B
  4. Quick Check:

    echo prints text = Hello, World! [OK]
Hint: echo prints text inside quotes [OK]
Common Mistakes:
  • Expecting PHP code to show as text
  • Thinking code causes error without semicolon
4. Find the error in this PHP code:
<?php
 echo "Welcome to PHP!"
?>
medium
A. Echo cannot print strings
B. Wrong opening PHP tag
C. Missing semicolon after echo statement
D. Quotes should be single quotes

Solution

  1. Step 1: Check PHP syntax rules

    Each statement must end with a semicolon to separate commands.
  2. Step 2: Identify missing semicolon

    The echo line lacks a semicolon at the end, causing a syntax error.
  3. Final Answer:

    Missing semicolon after echo statement -> Option C
  4. Quick Check:

    Statements end with ; = Missing semicolon [OK]
Hint: Every PHP statement ends with a semicolon [OK]
Common Mistakes:
  • Ignoring semicolon at line end
  • Thinking double quotes cause error
5. You want to create a PHP page that shows the current year dynamically. Which code snippet correctly does this?
hard
A. <?php echo date('Y'); ?>
B. <?php print currentYear(); ?>
C. <?php echo 'year'; ?>
D. <?php showYear(); ?>

Solution

  1. Step 1: Identify PHP function for current year

    The built-in function date('Y') returns the current year as a string.
  2. Step 2: Check code snippets

    Only <?php echo date('Y'); ?> uses date('Y') correctly with echo to print the year.
  3. Final Answer:

    <?php echo date('Y'); ?> -> Option A
  4. Quick Check:

    date('Y') prints year = <?php echo date('Y'); ?> [OK]
Hint: Use date('Y') to get current year in PHP [OK]
Common Mistakes:
  • Using undefined functions like currentYear()
  • Printing literal strings instead of function output
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard