php验证银行卡号码的正确性、规范性

分享一个PHP验证银行卡号的方法

public function checkbank($no=""){
    if(empty($no)) return false;
    $arr_no = str_split($no);
    $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.webstr.top/post/69.html

posted @ 2019-11-03 17:46  wx_9uxYUbHk2m  阅读(1)  评论(0编辑  收藏  举报  来源