Count the number of vowels occurring in all the substrings of given string | Returns the total sum of occurrences of all vowels ; No . of occurrences of 0 th character in all the substrings ; No . of occurrences of ith character in all the substrings ; Check if ith character is a vowel ; Return the total sum of occurrences of vowels ; Driver Code
< ? php function vowel_calc ( $ s ) { $ n = strlen ( $ s ) ; $ arr = array ( ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ i == 0 ) $ arr [ $ i ] = $ n ; else $ arr [ $ i ] = ( $ n - $ i ) + $ arr [ $ i - 1 ] - $ i ; } $ sum = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ s [ $ i ] == ' a ' $ s [ $ i ] == ' e ' $ s [ $ i ] == ' i ' $ s [ $ i ] == ' o ' $ s [ $ i ] == ' u ' ) $ sum += $ arr [ $ i ] ; } return $ sum ; } $ s = " daceh " ; echo ( vowel_calc ( $ s ) ) ; ? >