Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 15, 2020 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/59a03e2f7e60706a5f90536721437bb7 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/59a03e2f7e60706a5f90536721437bb7 to your computer and use it in GitHub Desktop.
Just PHP FUN 103.
<?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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment