Bird
0
0

What will the following PHP code output?

medium📝 Predict Output Q4 of 15
PHP - Superglobals and Web Context
What will the following PHP code output?
<?php
$_POST['user'] = 'Bob';
echo isset($_POST['user']) ? $_POST['user'] : 'Guest';
?>
ANotice error
BBob
CGuest
DEmpty string
Step-by-Step Solution
Solution:
  1. Step 1: Check if 'user' key exists in $_POST and output the value if set, else 'Guest'

    The code sets $_POST['user'] to 'Bob', so isset($_POST['user']) returns true. Since 'user' is set, echo outputs 'Bob'.
  2. Final Answer:

    Bob -> Option B
  3. Quick Check:

    isset($_POST['user']) = true, output = 'Bob' [OK]
Quick Trick: isset checks if key exists before accessing [OK]
Common Mistakes:
  • Assuming 'Guest' prints without checking isset
  • Expecting error due to direct access
  • Confusing $_POST with $_GET

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes