public function calcChecksum($input)
    {
        $wi = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        $sum = 0;

        for ($i = 16; $i >= 0; $i--) {
            $sum += $input[$i] * $wi[$i];
        }

        $checksum = (12 - $sum % 11) % 11;

        return $checksum == 10 ? 'X' : (string)$checksum;
    }
public function calcChecksum($input)
    {
        $wi = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        $sum = 0;

        for ($i = 16; $i >= 0; $i--) {
            $sum += $input[$i] * $wi[$i];
        }

        $checksum = (12 - $sum % 11) % 11;

        return $checksum == 10 ? 'X' : (string)$checksum;
    }
public function calcChecksum ( $ input ) { $ wi = array ( 7 , 9 , 10 , 5 , 8 , 4 , 2 , 1 , 6 , 3 , 7 , 9 , 10 , 5 , 8 , 4 , 2 ) ; $ sum = 0 ; for ( $ i = 16 ; $ i >= 0 ; $ i -- ) { $ sum += $ input [ $ i ] * $ wi [ $ i ] ; } $ checksum = ( 12 - $ sum % 11 ) % 11 ; return $ checksum == 10 ? 'X' : ( string ) $ checksum ; }
Calculate the final digit of id card

@param string $input The 17 or 18-digit code
@return string
Calculate the final digit of id card