Reverse the order of space-separated words in a string

Try this:

$s="Hello everybody in stackoverflow";
echo implode(' ', array_reverse(explode(' ', $s)));

Leave a Comment