Check whether second string can be formed from characters of first string | PHP program to check whether second string can be formed from first string ; Create a count array and count frequencies characters in str1 . ; Now traverse through str2 to check if every character has enough counts ; Driver Code
< ? php $ MAX = 256 ; function canMakeStr2 ( $ str1 , $ str2 ) { $ count = ( 0 ) ; for ( $ i = 0 ; $ i < strlen ( $ str1 ) ; $ i ++ ) for ( $ i = 0 ; $ i < strlen ( $ str2 ) ; $ i ++ ) { if ( $ count [ $ str2 [ $ i ] ] == 0 ) return -1 ; } return true ; } $ str1 = " geekforgeeks " ; $ str2 = " for " ; if ( canMakeStr2 ( $ str1 , $ str2 ) ) echo " Yes " ; else echo " No " ; ? >