I have an array that looks like this
mainArray =>
[a] =>
[A]
[B]
[C]
[b] =>
[D]
[E]
[F]
[c] =>
[G]
[H]
[I]
I want to put these into an array like this:
secondArray =>
[0] => { [A], [D], [G] }
[1] => { [A], [E], [G] }
.
.
.
[n] => { [C], [F], [I] }
I am having trouble figuring out how to get the right number of elements in $secondArray that start with a certain element in { [A],[B], .. }. For example, how many start with [A].
This is what I think I have to do:
secondArray =>
[0] =>
[A]
secondArray =>
[0] =>
[A]
[D]
secondArray =>
[0] =>
[A]
[D]
[G]
secondArray =>
[0] =>
[A]
[D]
[G]
[1] =>
[A]
[D]
[H]
secondArray =>
[0] =>
[A]
[D]
[G]
[1] =>
[A]
[D]
[H]
[2] =>
[A]
[D]
[I]
secondArray =>
[0] =>
[A]
[D]
[G]
[1] =>
[A]
[D]
[H]
[2] =>
[A]
[D]
[I]
[3] =>
[A]
[E]
[G]
[4] =>
[A]
[E]
[H]
[5] =>
[A]
[E]
[I]
secondArray =>
[0] =>
[A]
[D]
[G]
[1] =>
[A]
[D]
[H]
[2] =>
[A]
[D]
[I]
[3] =>
[A]
[E]
[G]
[4] =>
[A]
[E]
[H]
[5] =>
[A]
[E]
[I]
[6] =>
[A]
[F]
[G]
[7] =>
[A]
[F]
[H]
[8] =>
[A]
[F]
[I]
and so on, but I can’t really think of how to implement it…
Any help would be appreciated
You can generate the elements sequentially.
To implement the iterator:
If you do want all combinations at once, the code simplifies slightly: