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
$name = "John";
echo "Hello, $name!";
?>
AError
BHello, $name!
CHello, name!
DHello, John!
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable interpolation in double quotes

    PHP replaces $name with its value inside double quotes.
  2. Step 2: Output the string with variable value

    So echo prints Hello, John! exactly.
  3. Final Answer:

    Hello, John! -> Option D
  4. Quick Check:

    Variable interpolation = Hello, John! [OK]
Quick Trick: Variables inside "" are replaced by their values [OK]
Common Mistakes:
  • Using single quotes which don't interpolate
  • Forgetting $ before variable
  • Syntax errors in echo statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes