- https://www.codewars.com/kata/58d76854024c72c3e20000de Reverse every other word in the string.
Started at 21:03 15.09.2020 Tuesday Sep.
Finished at 21:16 15.03.2020 Tuesday Sep. (0hrs 13minutes)
Started at 21:03 15.09.2020 Tuesday Sep.
Finished at 21:16 15.03.2020 Tuesday Sep. (0hrs 13minutes)
<?php | |
# https://www.codewars.com/kata/58d76854024c72c3e20000de Reverse every other word in the string. | |
function reverse($str) { | |
$str = trim($str); $str = preg_replace('/\s+/'," ",$str); | |
$arr = explode(" ",$str); | |
foreach($arr as $i=>$word) if(1 == $i%2) $arr[$i] = strrev($word); | |
return implode(" ",$arr); | |
} |