Example #1
0
function countCombinations(array $data, $total, &$count)
{
    while (count($data) > 0) {
        $remaining = $total - array_shift($data);
        if ($remaining > 0) {
            countCombinations($data, $remaining, $count);
        } elseif ($remaining === 0) {
            $count++;
        }
    }
}
Example #2
0
function countCombinations(array $data, $total, array &$counts, $num = 1)
{
    while (count($data) > 0) {
        $remaining = $total - array_shift($data);
        if ($remaining > 0) {
            countCombinations($data, $remaining, $counts, $num + 1);
        } elseif ($remaining === 0) {
            $counts[$num]++;
        }
    }
}