Bird
0
0

What will the following PHP code output if the URL is page.php?name=Alice?

medium📝 Predict Output Q13 of 15
PHP - Superglobals and Web Context
What will the following PHP code output if the URL is page.php?name=Alice?
<?php
echo 'Hello, ' . $_GET['name'];
?>
AHello, Alice
BHello,
CNotice: Undefined index: name
DSyntax Error
Step-by-Step Solution
Solution:
  1. Step 1: Identify the URL parameter

    The URL has name=Alice, so $_GET['name'] will be 'Alice'.
  2. Step 2: Understand the echo statement

    The code concatenates 'Hello, ' with the value of $_GET['name'], so it prints 'Hello, Alice'.
  3. Final Answer:

    Hello, Alice -> Option A
  4. Quick Check:

    URL param 'name' = 'Alice' outputs greeting [OK]
Quick Trick: Echo $_GET['param'] prints URL parameter value [OK]
Common Mistakes:
  • Assuming empty output if parameter exists
  • Confusing undefined index error when parameter is present
  • Thinking code causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes