text: Permute a string by changing case | Function to generate permutations ; Number of permutations is 2 ^ n ; Converting string to lower case ; Using all subsequences and permuting them ; If j - th bit is set , we convert it to upper case ; Printing current combination ; Driver Code
code: < ? php function permute ( $ input ) { $ n = strlen ( $ input ) ; $ max = 1 << $ n ; $ input = strtolower ( $ input ) ; for ( $ i = 0 ; $ i < $ max ; $ i ++ ) { $ combination = $ input ; for ( $ j = 0 ; $ j < $ n ; $ j ++ ) { if ( ( ( $ i >> $ j ) & 1 ) == 1 ) $ combination [ $ j ] = chr ( ord ( $ combination [ $ j ] ) - 32 ) ; } echo $ combination . " " ; } } permute ( " ABC " ) ; ? >