Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Output and String Handling
What will be the output of this PHP code?
$name = "Bob";
$text = <<
AHello, ;
BHello, $name!
CSyntax error
DHello, Bob!
Step-by-Step Solution
Solution:
  1. Step 1: Understand heredoc variable parsing

    Heredoc parses variables like double quotes, so $name will be replaced by "Bob".
  2. Step 2: Output the string

    The string becomes "Hello, Bob!" and is printed by echo.
  3. Final Answer:

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

    Heredoc variable parsing = replaced [OK]
Quick Trick: Heredoc parses variables like double quotes [OK]
Common Mistakes:
  • Expecting literal $name output
  • Thinking heredoc causes syntax error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes