Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
PHP - String Functions
Identify the error in this code:
$parts = explode(';', 'apple;banana;orange');
echo $parts[3];
ASyntax error in explode() usage
BUndefined offset error because index 3 does not exist
CDelimiter should be comma, not semicolon
Dexplode() returns string, not array
Step-by-Step Solution
Solution:
  1. Step 1: Check explode() result array size

    Splitting 'apple;banana;orange' by ';' gives 3 elements at indexes 0,1,2.
  2. Step 2: Accessing index 3 causes error

    Index 3 does not exist, so PHP throws undefined offset notice.
  3. Final Answer:

    Undefined offset error because index 3 does not exist -> Option B
  4. Quick Check:

    Accessing non-existent array index causes error [OK]
Quick Trick: Array indexes start at 0; check length before access [OK]
Common Mistakes:
  • Accessing out-of-range index
  • Wrong delimiter assumption
  • Expecting explode to return string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes