/** * [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是通过