iterate and mark the frequencies of all characters in str1
for ( $ i = 0 ; $ i < $ l1 ; $ i ++ ) $ freq [ ord ( $ str1 [ $ i ] ) - ord ( ' a ' ) ] += 1 ; for ( $ i = 0 ; $ i < $ l2 ; $ i ++ ) $ freq2 [ ord ( $ str2 [ $ i ] ) - ord ( ' a ' ) ] += 1 ; $ count = PHP_INT_MAX ;