Sum of the alphabetical values of the characters of a string | Function to find string score ; Driver code
< ? php function strScore ( $ str , $ s , $ n ) { $ score = 0 ; $ index ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ str [ $ i ] == $ s ) { for ( $ j = 0 ; $ j < strlen ( $ s ) ; $ j ++ ) $ score += ( ord ( $ s [ $ j ] ) - ord ( ' a ' ) ) + 1 ; $ index = ( $ i + 1 ) ; break ; } } $ score = $ score * $ index ; return $ score ; } $ str = array ( " sahil " , " shashanak " , " sanjit " , " abhinav " , " mohit " ) ; $ s = " abhinav " ; $ n = sizeof ( $ str ) ; $ score = strScore ( $ str , $ s , $ n ) ; echo $ score , " STRNEWLINE " ; ? >