Bird
0
0

What is the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - String Functions
What is the output of the following PHP code?
$str = "one,two,three,four";
$result = explode(",", $str, 3);
print_r($result);
AArray ( [0] => one [1] => two [2] => three,four )
BArray ( [0] => one [1] => two [2] => three )
CArray ( [0] => one,two [1] => three [2] => four )
DArray ( [0] => one [1] => two [2] => three [3] => four )
Step-by-Step Solution
Solution:
  1. Step 1: Understand explode() with limit parameter

    The third parameter limits the number of pieces. Here, limit=3 means maximum 3 parts.
  2. Step 2: Apply limit to splitting

    The string splits at first two commas: 'one', 'two', and the rest 'three,four' stays as last part.
  3. Final Answer:

    Array ( [0] => one [1] => two [2] => three,four ) -> Option A
  4. Quick Check:

    explode(',', string, 3) limits to 3 parts [OK]
Quick Trick: Limit splits into max parts; last part keeps rest [OK]
Common Mistakes:
  • Ignoring the limit parameter effect
  • Expecting all parts split regardless of limit
  • Confusing array keys or values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes