php
php copied to clipboard
Example on line 39 of /concepts/arrays/about.md contains incorrect result
I'm currently learning PHP by following along with Exercism's learning track, and noticed a discrepancy between the example on line 39 and PHP's documentation on the explode function.
This is the URL on Exercism: https://exercism.org/tracks/php/concepts/arrays
Exercism's documentation says: $letters = explode("Hello", ""); // => ["H", "e", "l", "l", "o"]
I've tried setting $letters
as in Exercism's example, and then print_r($letters)
in the browser code editor, and I get an empty array.
PHP's documentation seems to suggest that either an empty array would be returned (if the limit parameter is negative), or ["Hello"]
would be returned. I'm specifically referring to the Return Values section.
If this example should be kept, I think it could be corrected like this: $letters = str_split("Hello"); //=> ["H", "e", "l", "l", "o"]
Please let me know if that solution is desirable- I can submit a pull request. (In fact, I'd like to contribute if possible.)
Hi @kristin-wiseman, welcome to the PHP track!
Thanks for pointing this out. In fact, explode()
expects arguments in opposite order of what is shown in the concept text. So you get an array with an empty string (the empty string is not visible in print_r()
output, use var_dump()
to see it). Nevertheless, it's a wrong example using a forbidden empty separator.
If you want to make a pull request, please use the mb_str_split()
function. And adjust the link to the documentation in that concept.
Thanks for wanting to contribute!