I'm having an issue creating a function that both reverses the input string AND preserves any extra spaces in it. For example:
reverse("this is a string"); // should return: "siht si a gnirts"
And if we have something like:
reverse("this is a string"); // then should be: "siht si a gnirts"
But I'm hitting a brick wall mentally coming up with how to account for both. I know it should be easy .. I feel stupid :/
Here is what I have so far (only works for the first part):
function reverseWords($str) {
return implode(' ', array_reverse(explode(' ', strrev($str)))) ;
}