Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Type Handling
What will be the output of this PHP code?
$a = '5';
$b = 3;
echo $a + $b;
A53
B8
CError
D5 3
Step-by-Step Solution
Solution:
  1. Step 1: Identify variable types and operation

    $a is a string '5', $b is integer 3, operation is addition (+).
  2. Step 2: Understand PHP type juggling in addition

    PHP converts string '5' to integer 5, then adds 3 to get 8.
  3. Final Answer:

    8 -> Option B
  4. Quick Check:

    String + int = numeric addition [OK]
Quick Trick: Adding string and int converts string to number [OK]
Common Mistakes:
  • Expecting string concatenation with +
  • Thinking output is '53' as string concat
  • Assuming error due to mixed types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes