I have to make a complex array with other array values.
The original array is:
Array (
[0] => Array (
[0] => A
[1] => B
[2] => C
)
[1] => Array (
[0] => D
[1] => E
[2] => F
)
)
I'm looking for a function which give me all combinations values possible, like this:
Array (
[0] => Array (A, D),
[1] => Array (A, E),
[2] => Array (A, F),
[3] => Array (B, D),
[4] => Array (B, E),
[5] => Array (B, F),
[6] => Array (C, D),
[7] => Array (C, E),
[8] => Array (C, F)
)
Of course, this algo must work even if the numbers of values in the original array are different.
I'm looking for a simple function in PHP documentation for doing this, but I did not find one.
I've Googled it with keywords like "multiplex" or "combine" but with no luck. I think the best way is to make a recursive function, but I can't find the correct algo.
A simple recursive function to calculate cartesian product:
Output