Recursive Digit Sum

  • + 0 comments

    php

    function superDigit($n, $k) {
        $x = array_sum(str_split($n)) * $k;
    
        while ($x >= 10) {
            $x = array_sum(str_split($x));
        }
    
        return $x;
    }