1. 直接用
function check_bankCard($cardNo){
$arr_no = str_split($cardNo);
$last_n = $arr_no[count($arr_no)-1];
krsort($arr_no);
$i = 1;
$total = 0;
foreach ($arr_no as $n){
if($i%2==0){
$ix = $n*2;
if($ix>=10){
$nx = 1 + ($ix % 10);
$total += $nx;
}else{
$total += $ix;
}
}else{
$total += $n;
}
$i++;
}
$total -= $last_n;
$x = 10 - ($total % 10);
if($x == $last_n){
return true;
}else{
return false;
}
}
来源:http://www.voidcn.com/article/p-tlkcjzdg-ws.html
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。