Jak-S
07-21-2006, 05:09 PM
Hi,
Can anyone help me out with this, I can’t get my head round it.
I have an array, it can have any number of elements, and each element contains another array which can also contain any number of elements, here is an example array:
array(6) {
[0]=>
array(1) {
[0]=>
string(1) "6"
}
[1]=>
array(1) {
[0]=>
string(2) "19"
}
[2]=>
array(1) {
[0]=>
string(2) "23"
}
[3]=>
array(1) {
[0]=>
string(2) "38"
}
[4]=>
array(4) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "9"
[3]=>
string(2) "10"
}
[5]=>
array(4) {
[0]=>
string(1) "3"
[1]=>
string(2) "11"
[2]=>
string(2) "14"
[3]=>
string(2) "17"
}
}
What I need to do is write some sort of recursive script that can generate an array of every single possible combination of the elements in the child arrays, so something like this:
6, 19, 23, 38, 1, 3
6, 19, 23, 38, 1, 11
6, 19, 23, 38, 1, 14
6, 19, 23, 38, 1, 14
6, 19, 23, 38, 2, 3
6, 19, 23, 38, 2, 11
6, 19, 23, 38, 2, 14
6, 19, 23, 38, 2, 14
6, 19, 23, 38, 9, 3
6, 19, 23, 38, 9, 11
etc…..
I don’t need the same sets of numbers in different orders, just the unique combinations. The output would again be an array with child arrays, one element in the main array for each combination, and then the child arrays will have an element for each separate number.
If anyone can help me out that would be great. Thanks,
Jack
Can anyone help me out with this, I can’t get my head round it.
I have an array, it can have any number of elements, and each element contains another array which can also contain any number of elements, here is an example array:
array(6) {
[0]=>
array(1) {
[0]=>
string(1) "6"
}
[1]=>
array(1) {
[0]=>
string(2) "19"
}
[2]=>
array(1) {
[0]=>
string(2) "23"
}
[3]=>
array(1) {
[0]=>
string(2) "38"
}
[4]=>
array(4) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "9"
[3]=>
string(2) "10"
}
[5]=>
array(4) {
[0]=>
string(1) "3"
[1]=>
string(2) "11"
[2]=>
string(2) "14"
[3]=>
string(2) "17"
}
}
What I need to do is write some sort of recursive script that can generate an array of every single possible combination of the elements in the child arrays, so something like this:
6, 19, 23, 38, 1, 3
6, 19, 23, 38, 1, 11
6, 19, 23, 38, 1, 14
6, 19, 23, 38, 1, 14
6, 19, 23, 38, 2, 3
6, 19, 23, 38, 2, 11
6, 19, 23, 38, 2, 14
6, 19, 23, 38, 2, 14
6, 19, 23, 38, 9, 3
6, 19, 23, 38, 9, 11
etc…..
I don’t need the same sets of numbers in different orders, just the unique combinations. The output would again be an array with child arrays, one element in the main array for each combination, and then the child arrays will have an element for each separate number.
If anyone can help me out that would be great. Thanks,
Jack