Пример с использованием класса.
class CombinationsCalculator
{
protected $result;
protected $combination;
public function getCombinations($array, $group) {
$this->result = [];
$this->combination = [];
$this->iteration(0, $group, $array, count($array));
return $this->result;
}
protected function iteration($start, $step, $array, $n) {
if ($step == 0) {
array_push($this->result,$this->combination);
}
else {
for ($i = $start; $i <= $n - $step; ++$i) {
array_push($this->combination, $array[$i]);
$this->iteration($i + 1, $step - 1, $array, $n);
array_pop($this->combination);
}
}
}
}
$calculator = new CombinationsCalculator();
$result = $calculator->getCombinations([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 8);