Count strings with consonants and vowels at alternate position | Function to find the count of strings ; Variable to store the final result ; Loop iterating through string ; If ' $ ' is present at the even position in the string ; ' sum ' is multiplied by 21 ; If ' $ ' is present at the odd position in the string ; ' sum ' is multiplied by 5 ; Let the string ' str ' be s$$e$ ; Print result
< ? php function countStrings ( $ s ) { $ sum = 1 ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; $ i ++ ) { if ( $ i % 2 == 0 && $ s [ $ i ] == ' $ ' ) $ sum *= 21 ; else if ( $ s [ $ i ] == ' $ ' ) $ sum *= 5 ; } return $ sum ; } $ str = " s\ $ \ $ e\ $ " ; echo countStrings ( $ str ) ; ? >