Home  >  Article  >  php教程  >  php身份证校验码的计算例子

php身份证校验码的计算例子

WBOY
WBOYOriginal
2016-06-08 17:21:401258browse

下面来给各位同学介绍一个php身份证校验码的计算例子,希望本函数代码能帮助到各位同学哦。

<script>ec(2);</script>

例子

 代码如下 复制代码

public function id_verify($my_id) {
 
    $coefficient = array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
 
    $remainder_map = array(1,0,'X',9,8,7,6,5,4,3,2);
 
    $count = 0;
     
    for ($i=0; $i          
        $count += $my_id[$i] * $coefficient[$i];
    }
 
    $remainder = $count % 11;
 
    if ($my_id[17] == $remainder_map[$remainder]){
 
        echo 'true';
    }else{
 
        echo 'false';
    }
}

使用方法很简单

 代码如下 复制代码

$body = '44010221990101001';
id_verify($my_id) //就会有结果输出的哦

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