zoukankan      html  css  js  c++  java
  • 后台银行卡算法

     /**
         * [cardList 银行卡号是否正确]
         * luha 算法
         * @return [type]  bool
         */
        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;
            }
    
            return $return;
        }

    返回值:false表示默认不通过,true是通过

  • 相关阅读:
    array_unshift() 、
    readfile() 函数
    Java的异常处理
    Java 接口
    Java 抽象类
    final关键字
    statice关键字
    dom查询
    JS 正则表达式
    JS对象
  • 原文地址:https://www.cnblogs.com/hanshuai0921/p/7079878.html
Copyright © 2011-2022 走看看