当前位置:Gxlcms > PHP教程 > 身份证校验码的计算

身份证校验码的计算

时间:2021-07-01 10:21:17 帮助过:7人阅读

原来我的ID最后一位X其实是2了。
  1. public function id_verify($my_id) {
  2. $coefficient = array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
  3. $remainder_map = array(1,0,'X',9,8,7,6,5,4,3,2);
  4. $count = 0;
  5. for ($i=0; $i < 17; $i++) {
  6. $count += $my_id[$i] * $coefficient[$i];
  7. }
  8. $remainder = $count % 11;
  9. if ($my_id[17] == $remainder_map[$remainder]){
  10. echo 'true';
  11. }else{
  12. echo 'false';
  13. }
  14. }

人气教程排行