Possible Duplicate:
algorithm that will take numbers or words and find all possible combinations
If I have an array such as:
array('a', 'b', 'c', 'd');
How would I create a new array with all possible combinations of those 4 values such as
aaaa, aaab, aaac, aaad ... dddb, dddc, dddd
Thanks!
Here’s another way.
This function increments in base( [number of elements in array] )
and uses the strtr function to swap out the characters for strings.
Then …
This also seems to be significantly faster than the recursive example below.
Using microtime() on my server this code runs in 0.072862863540649 seconds
The recursive example below takes 0.39673089981079 seconds.
138% faster!