后台验证银行卡号算法

public static function check_card($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;
        $total *= 9;

        if($last_n == ($total%10)){
            $return = true;
        }
       // var_dump($return);
        return $return;
    }

这里验证的前提需要保证银行卡号不能为空和0

原文地址:https://www.cnblogs.com/hanshuai0921/p/6812006.html