I have an apparently easy task, but I'm stuck. I tried restructures and iterators, but no ideas struck me. They say a picture's worth a thousand words, so I'll show my 'picture' example array:
array (size=4)
0 =>
array (size=4)
0 => int 1
1 => int 2
2 => int 3
3 => int 4
1 =>
array (size=3)
0 => string 'a' (length=1)
1 => string 'b' (length=1)
2 => string 'c' (length=1)
2 =>
array (size=3)
0 => string 'X' (length=1)
1 => string 'Y' (length=1)
2 => string 'Z' (length=1)
3 =>
array (size=5)
0 => string '!' (length=1)
1 => string '"' (length=1)
2 => string '#' (length=1)
3 => string '$' (length=1)
4 => string '%' (length=1)
The rules:
- The array size and sub arrays sizes are random, and quite huge.
- Only one value from any sub array can be used.
- Results should be ordered from shortest string to longest.
- Must be memory efficient, due to huge data being generated, results should be stored / compared offline, like a file or mysql db. But each at a time.
An example of the desired string combinations:
1
2
3
4
a
b
c
X ...
1a
1b
1c
2a
2b ...
aX!
aX" ...
1aX!
1aX" .......
4cZ%
I tried several iterators like How to generate in PHP all combinations of items in multiple arrays.