Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q5 of 15
PHP - Basics and Execution Model
What will this PHP code output?
<?php
$greeting = "Hello World!";
echo $greeting;
?>
AError: Undefined variable
BHello World!
C$greeting
DHelloWorld!
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable assignment and echo

    The variable $greeting stores the string "Hello World!".
  2. Step 2: Echo prints the variable's value

    Using echo $greeting; outputs the stored string exactly.
  3. Final Answer:

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

    Variable output = Hello World! [OK]
Quick Trick: Variables start with $ and hold values [OK]
Common Mistakes:
  • Printing variable name as string
  • Missing $ sign on variable
  • Not assigning value before echo

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes