Generate all binary strings from given pattern | Recursive function to generate all binary strings formed by replacing each wildcard character by 0 or 1 ; replace ' ? ' by '0' and recurse ; replace ' ? ' by '1' and recurse ; No need to backtrack as string is passed by value to the function ; Driver code
< ? php function print1 ( $ str , $ index ) { if ( $ index == strlen ( $ str ) ) { echo $ str . " STRNEWLINE " ; return ; } if ( $ str [ $ index ] == ' ? ' ) { $ str [ $ index ] = '0' ; print1 ( $ str , $ index + 1 ) ; $ str [ $ index ] = '1' ; print1 ( $ str , $ index + 1 ) ; } else print1 ( $ str , $ index + 1 ) ; } $ str = "1 ? ? 0?101" ; print1 ( $ str , 0 ) ; ? >