Reverse the letters in each word of a string

This should work:

$words = explode(' ', $string);
$words = array_map('strrev', $words);
echo implode(' ', $words);

Or as a one-liner:

echo implode(' ', array_map('strrev', explode(' ', $string)));

Leave a Comment