Bird
0
0

Identify the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - Type Handling
Identify the error in this PHP code:
$a = '10 apples';
$b = 'five';
$c = $a + $b;
echo $c;
ANo error, outputs 10
BError because 'five' is non-numeric
COutputs '10five'
DOutputs 15
Step-by-Step Solution
Solution:
  1. Step 1: Convert operands to numbers

    '10 apples' converts to 10; 'five' converts to 0 because it's non-numeric.
  2. Step 2: Add 10 + 0

    Result is 10.
  3. Final Answer:

    No error, outputs 10 -> Option A
  4. Quick Check:

    Non-numeric strings convert to 0 in math [OK]
Quick Trick: Non-numeric strings become 0 in arithmetic [OK]
Common Mistakes:
  • Expecting error on non-numeric string
  • Thinking concatenation happens
  • Assuming output is string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes