We're a place where coders share, stay up-to-date and grow their careers.
Here is the simple solution with PHP:
function toWeirdCase($string) { $strings = explode(' ', $string); $stringsIndex = 0; foreach ($strings as $string) { $index = 0; for (; $index < strlen($string); $index++) { if ($index % 2 === 0) { $string[$index] = strtoupper($string[$index]); } else { $string[$index] = strtolower($string[$index]); } } $strings[$stringsIndex] = $string; $stringsIndex++; } return implode(' ', $strings); }
Here is the simple solution with PHP: