0
0
PHPprogramming~5 mins

String split and explode in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the explode() function do in PHP?
The explode() function splits a string into an array using a specified delimiter.
Click to reveal answer
beginner
How do you split a string by spaces using explode()?
Use explode(' ', $string) to split the string at each space character.
Click to reveal answer
intermediate
What is the difference between explode() and str_split()?
explode() splits a string by a delimiter into an array of substrings. <br>str_split() splits a string into an array of single characters or fixed-length chunks.
Click to reveal answer
beginner
What will explode(',', 'apple,banana,orange') return?
It returns an array: ['apple', 'banana', 'orange'] splitting the string at each comma.
Click to reveal answer
intermediate
Can explode() handle an empty delimiter?
No, explode() requires a non-empty string as the delimiter. Passing an empty string will cause a warning.
Click to reveal answer
Which function splits a string into an array by a delimiter in PHP?
Asubstr()
Bimplode()
Cstr_replace()
Dexplode()
What does explode('-', '2024-06-15') return?
A['2024', '06', '15']
B'2024-06-15'
C['2024-06-15']
D['2024', '-06', '-15']
What happens if the delimiter is not found in the string when using explode()?
AThrows an error
BReturns an empty array
CReturns an array with the original string as the only element
DReturns null
Which function splits a string into single characters or fixed-length chunks?
Astr_split()
Bexplode()
Csubstr()
Dimplode()
What is the correct way to split a CSV string into an array?
Aexplode(' ', $csvString)
Bexplode(',', $csvString)
Cstr_split($csvString)
Dimplode(',', $csvString)
Explain how the explode() function works and give an example.
Think about how you cut a sentence into words using spaces.
You got /4 concepts.
    Describe the difference between explode() and str_split() in PHP.
    One splits by a character or string, the other by length.
    You got /3 concepts.