Home >Backend Development >PHP Tutorial >Calculation of ID card verification code

Calculation of ID card verification code

WBOY
WBOYOriginal
2016-07-25 08:47:34863browse
It turns out that the last X in my ID is actually 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. }
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn