Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$csv = 'red,green,,blue';
$parts = explode(',', $csv);
echo count($parts), ' ', implode('|', array_slice($parts, 1, 2)), "\n";4 green|
- Expecting
explodeto skip the empty piece between two commas: it returns every piece, the empty string included, so'red,green,,blue'gives four parts. - Reading the third argument of
array_sliceas an end position: it is the number of elements, soarray_slice($parts, 1, 2)takes the parts at positions1and2.
- How would you drop the empty pieces after
explode? - What does
explodereturn for a string that has no separator in it?