// Input array
$arr = [
'A' => '9-11',
'B' => '9-12',
'C' => '12-14',
'D' => '13-14',
'E' => '15-16',
'F' => '15-16',
'G' => '13-14',
'H' => '14-16'
];
// ranges
$start = 9;
$end = 16;
// Desired outputs:
A + C + E (9-11, 12-14, 15-16)
A + C + F (9-11, 12-14, 15-16)
A + C + H (9-11, 12-14, 14-16)
B + D + E (9-12, 13-14, 15-16)
B + G + F (9-12, 13-14, 15-16)
B + G + H (9-12, 13-14, 14-16)
So it means, every combination MUST start with 9 ( as we $start = 9
) and try to get up to 16 ( ie. the $end = 16
IF AVAILABLE ) with n
elements in each combination( here, n = 3
).
I searched the web for many problems and tried something of myself. But unfortunately, they didn't even get a title bit closer of the solution. The problem I'm working is different from above example and complex.