Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
PHP - String Functions
What will be the output of this code?
$str = 'a,b,c,d';
$result = explode(',', $str, 2);
print_r($result);
AArray ( [0] => a [1] => b [2] => c [3] => d )
BArray ( [0] => a,b,c,d )
CArray ( [0] => a [1] => b,c,d )
DArray ( [0] => a,b [1] => c,d )
Step-by-Step Solution
Solution:
  1. Step 1: Understand explode() with limit parameter

    Limit 2 means split into maximum 2 parts; first split at first comma.
  2. Step 2: Apply limit to string

    First part is 'a', second part is the rest 'b,c,d'.
  3. Final Answer:

    Array ( [0] => a [1] => b,c,d ) -> Option C
  4. Quick Check:

    explode with limit splits into max parts [OK]
Quick Trick: Limit in explode() controls max array size [OK]
Common Mistakes:
  • Ignoring limit parameter
  • Expecting full split despite limit
  • Confusing limit with offset

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes