I have the following array:
1 => array
0 => string '1'
1 => string '2'
2 => array
0 => string '7'
1 => string '8'
And I want to create some objects, in this case 4, size of the first times size of the second.
So I would get:
Object(1,7)
Object(1,8)
Object(1,7)
Object(2,8)
The problem is, I dont know the size of the first array so it could be like this
1 => array
0 => string '1'
1 => string '2'
2 => array
0 => string '7'
1 => string '8'
3 => array
0 => string '9'
1 => string '10'
So I would get:
Object(1,7,9)
Object(1,7,10)
Object(1,8,9)
Object(1,8,10)
Object(2,7,9)
Object(2,7,10)
Object(2,8,9)
Object(2,8,10)
And It could be even bigger.
Sorry for the bad explanation, I cant think of a better way to explain it.
So the question is, how would I go and implement this?
preferably in PHP but Java, C, C++ solutions are accepted since I can relatively easily convert them.
What you are looking for is the “cartesian product” of your arrays. The first step would be to do something like this: Concatenate values of n arrays in php
You would then have to convert the arrays to objects, which should not be a challenge.