19 lines
431 B
PHP
19 lines
431 B
PHP
<?php
|
|
function reverseWords(string $str): string
|
|
{
|
|
$words = explode(' ', $str);
|
|
$words = array_reverse($words);
|
|
return implode(' ', $words);
|
|
}
|
|
|
|
function reverseWords2(string $str): string
|
|
{
|
|
$words = explode(' ', $str);
|
|
foreach ($words as &$word) {
|
|
$word = strrev($word);
|
|
}
|
|
return implode(' ', $words);
|
|
}
|
|
|
|
echo reverseWords("The lazy dog") . PHP_EOL;
|
|
echo reverseWords2("The lazy dog") . PHP_EOL; |