$currYear) { return false; } return true; } /** * 验证18位身份证最后一位 * @param string $num 待校验的身份证号 * @return bool */ private static function isVerifyCodeValid(string $num) { if (strlen($num) == 18) { $factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; $tokens = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; $checkSum = 0; for ($i = 0; $i < 17; $i++) { $checkSum += intval($num{$i}) * $factor[$i]; } $mod = $checkSum % 11; $token = $tokens[$mod]; $lastChar = strtoupper($num{17}); if ($lastChar != $token) { return false; } } return true; } }