Wednesday, December 29, 2021

[FIXED] Reverse the order of space-separated words in a string

Issue

What would be the best way to reverse the order of space-separated words in a string?

Hello everybody in stackoverflow

becomes

stackoverflow in everybody Hello

Solution

Try this:

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


Answered By - Keith Gaughan

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.