Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q5 of 15
PHP - Output and String Handling
What will this PHP code output?
print("Sum: " . (2 + 3));
ASum: 2 + 3
BSum: 5
CSum:
DError: Syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the expression inside print

    The expression (2 + 3) evaluates to 5, then concatenated with "Sum: " results in "Sum: 5".
  2. Step 2: Understand print outputs the string

    print outputs the concatenated string correctly without errors.
  3. Final Answer:

    Sum: 5 -> Option B
  4. Quick Check:

    Expression evaluation + concatenation = Sum: 5 [OK]
Quick Trick: Expressions inside print are evaluated before output [OK]
Common Mistakes:
  • Thinking print outputs expression as text
  • Missing concatenation operator
  • Expecting syntax error due to parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes