checking if the frequency of the character at position i in x in b is greater than zero or not if zero we increase the prefix count by 1
if ( $ fr [ ord ( $ x [ $ i ] ) - 97 ] > 0 ) { $ c += 1 ; $ fr [ ord ( $ x [ $ i ] ) - 97 ] -= 1 ; } else break ; } echo $ c ; }