Check if the characters of a given string are in alphabetical order | Function that checks whether the string is in alphabetical order or not ; length of the string ; create a character array of the length of the string ; assign the string to character array ; sort the character array ; check if the character array is equal to the string or not ; Driver code ; check whether the string is in alphabetical order or not
< ? php Function isAlphabaticOrder ( $ s ) { $ n = strlen ( $ s ) ; $ c = array ( ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ c [ $ i ] = $ s [ $ i ] ; } sort ( $ c ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ c [ $ i ] != $ s [ $ i ] ) return false ; return true ; } $ s = " aabbbcc " ; if ( isAlphabaticOrder ( $ s ) ) echo " Yes " ; else echo " No " ; ? >