How can the logic for determining hits in a lottery system be improved to accurately account for different combinations and previous draws?

The logic for determining hits in a lottery system can be improved by creating a function that accurately accounts for different combinations and previous draws. This function should check each ticket against the winning numbers, considering all possible combinations and previous draws to determine the number of hits.

function countHits($ticket, $winningNumbers, $previousDraws) {
    $hits = 0;
    
    foreach($ticket as $number) {
        if(in_array($number, $winningNumbers)) {
            $hits++;
        }
    }

    foreach($previousDraws as $draw) {
        foreach($ticket as $number) {
            if(in_array($number, $draw)) {
                $hits++;
            }
        }
    }

    return $hits;
}

// Example of how to use the countHits function
$ticket = [3, 7, 12, 19, 25];
$winningNumbers = [7, 12, 19, 23, 30];
$previousDraws = [[2, 5, 12, 15, 21], [7, 12, 19, 22, 28]];

$hits = countHits($ticket, $winningNumbers, $previousDraws);
echo "Number of hits: " . $hits;