How can PHP be used to calculate single-digit cross sums with exceptions for certain numbers?

To calculate single-digit cross sums with exceptions for certain numbers in PHP, you can create a function that takes a number as input, checks if it is one of the exceptions, and calculates the cross sum accordingly. If the number is an exception, you can directly return that number as the cross sum. If it is not an exception, you can calculate the cross sum by adding the individual digits together until you get a single-digit result.

function calculateCrossSumWithExceptions($number, $exceptions) {
    if (in_array($number, $exceptions)) {
        return $number;
    } else {
        $crossSum = 0;
        $digits = str_split($number);
        
        foreach ($digits as $digit) {
            $crossSum += $digit;
        }

        while ($crossSum > 9) {
            $crossSum = array_sum(str_split($crossSum));
        }

        return $crossSum;
    }
}

// Example usage
$number = 12345;
$exceptions = [2, 4];
$result = calculateCrossSumWithExceptions($number, $exceptions);
echo "Cross sum of $number with exceptions " . implode(", ", $exceptions) . " is: $result";