There is a mapping of characters, like so:
$replacements = array(
array('a', 'b'), // a => b
array('a', 'c'), // a => c
array('b', 'n'),
array('c', 'x'),
);
And there is an input string, say “cbaa”. How can I get all combinations, where at least one character is replaced to one of its substitutes? In this example, “a” can be replaced to both “b” and “c”, so strings include:
xbaa
cnaa
xbba
cbca
cbab
cbac
...
xnaa
xnac
...
Here is an altered version of the code of Dmitry Tarasov (all credits to him please) which seems to be working properly.
The private function was introduced to avoid those heavy array operations to be executed multiple times, while they’re not used anywhere but from the root-call.