Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Output and String Handling
What will be the output of the following PHP code?
$fruit = "apple";
echo "I like $fruit pie.";
AI like apple pie.
BI like $fruit pie.
CI like $fruitpie.
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable interpolation in double quotes

    The variable $fruit inside double quotes will be replaced by its value "apple".
  2. Step 2: Check the output string

    The string becomes "I like apple pie." and is printed as is.
  3. Final Answer:

    I like apple pie. -> Option A
  4. Quick Check:

    Variable replaced by value = I like apple pie. [OK]
Quick Trick: Variables inside " " show their values [OK]
Common Mistakes:
  • Expecting variable name printed literally
  • Confusing variable concatenation without braces
  • Thinking it causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes