Let's start by listing what I looked at and what I'm not looking for.
I don't want to list all permutations from an array - Get all permutations of a PHP array?
I do not want to find all combinations in order from an array - stack overflow
The two examples above have led me to where I am now, but I'm still generating too many combinations. With 50 nodes, I get billions, if not trillions, of combinations, and I think I can reduce this with a tree structure.
What I'm looking for is all possible ordered combinations from a tree that can be structured as a multidimensional array like
[1]
--[2]
--[4]
[8]
--[3]
--[9]
----[5]
[6]
[7]
( / ). , - ,
node 1 2 4. 8 3 9. 9 8, 5. :
- 1
- 1.2.4
- 1.6.7.8
- 3.5.8.9
- 3.5.6.7.8.9
node, . , 1 , 2 4 . 9 , 5 , 8 , 3, 9 5 .
, node . , , , .
$arr = [];
$result = [];
$xtotal = 0;
$ytotal = 0;
$ztotal = 0;
for ($x=0; $x<2; $x++) {
$arr[$xtotal] = array();
$ytotal = $xtotal+1;
for ($y=0; $y<2; $y++) {
$arr[$xtotal][$ytotal] = array();
$ztotal = $ytotal+1;
for ($z=0; $z<2; $z++) {
$arr[$xtotal][$ytotal][$ztotal] = array();
$ztotal++;
}
$ytotal = $ztotal+1;
}
$xtotal = $ytotal+1;
}
for ($c=0; $c<5; $c++) {
$arr[$xtotal] = array();
$xtotal++;
}
, , , ?
EDIT: .
[1]
--[2]
--[4]
[8]
1
8
1.8
1.2
1.4
1.2.8
1.4.8
1.2.4
1.2.4.8