Modify the string by swapping continuous vowels or consonants | Function to check if a character is a vowel ; Function to swap two consecutively repeated vowels or consonants ; Traverse through the length of the string ; Check if the two consecutive characters are vowels or consonants ; swap the two characters ; Driver code
< ? php function isVowel ( $ c ) { $ c = strtolower ( $ c ) ; if ( $ c == ' a ' $ c == ' e ' $ c == ' i ' $ c == ' o ' $ c == ' u ' ) return true ; return false ; } function swapRepeated ( $ str ) { for ( $ i = 0 ; $ i < strlen ( $ str ) - 1 ; $ i ++ ) { if ( ( isVowel ( $ str [ $ i ] ) && isVowel ( $ str [ $ i + 1 ] ) ) || ( ! isVowel ( $ str [ $ i ] ) && ! isVowel ( $ str [ $ i + 1 ] ) ) ) { $ t = $ str [ $ i ] ; $ str [ $ i ] = $ str [ $ i + 1 ] ; $ str [ $ i + 1 ] = $ t ; } } return $ str ; } $ str = " geeksforgeeks " ; echo swapRepeated ( $ str ) ; return 0 ; ? >