Challenge - 5 Problems
String Split Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this PHP code using explode()?
Consider the following PHP code snippet. What will be the output when it runs?
PHP
<?php $str = "apple,banana,cherry"; $result = explode(",", $str); print_r($result); ?>
Attempts:
2 left
💡 Hint
explode() splits a string into an array using the delimiter.
✗ Incorrect
The explode function splits the string at each comma, creating an array with three elements: 'apple', 'banana', and 'cherry'.
❓ Predict Output
intermediate2:00remaining
What does this PHP code output when splitting with limit?
What will be the output of this PHP code?
PHP
<?php $str = "one,two,three,four"; $result = explode(",", $str, 3); print_r($result); ?>
Attempts:
2 left
💡 Hint
The third parameter limits the number of pieces returned.
✗ Incorrect
With limit=3, explode splits into maximum 3 parts. The last part contains the rest of the string.
🔧 Debug
advanced2:00remaining
What error does this PHP code raise?
What error will this PHP code produce when run?
PHP
<?php $str = "a|b|c"; $result = explode('|'); print_r($result); ?>
Attempts:
2 left
💡 Hint
explode() needs both delimiter and string parameters.
✗ Incorrect
explode() requires two parameters: the delimiter and the string to split. Missing the second causes a warning.
❓ Predict Output
advanced2:00remaining
What is the output of this PHP code using str_split()?
What will this PHP code output?
PHP
<?php $str = "hello"; $result = str_split($str, 2); print_r($result); ?>
Attempts:
2 left
💡 Hint
str_split splits string into chunks of given length.
✗ Incorrect
str_split with chunk length 2 splits 'hello' into 'he', 'll', and 'o'.
🧠 Conceptual
expert2:00remaining
How many elements are in the array after this explode() call?
Given the code below, how many elements does the resulting array have?
PHP
<?php $str = "one,,three,,five"; $result = explode(",", $str); ?>
Attempts:
2 left
💡 Hint
explode() includes empty strings between consecutive delimiters.
✗ Incorrect
The string has 4 commas, so explode creates 5 elements, including empty strings for empty parts.