美文网首页
验证银行卡号填写是否正确

验证银行卡号填写是否正确

作者: 聚米01 | 来源:发表于2022-05-11 13:28 被阅读0次

    function  bankCard($card_number){

            $arr_no = str_split($card_number);

            $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;

            }

        }

    相关文章

      网友评论

          本文标题:验证银行卡号填写是否正确

          本文链接:https://www.haomeiwen.com/subject/vdmdurtx.html