«

php计算大乐透中奖金额方法

时间:2024-2-20 10:14     作者:韩俊     分类: PHP


php计算大乐透中奖金额方法。

/**
 * @desc php计算大乐透中奖金额方法
 * @param string $buy_str 购买结果,类似 4+15+20+25+26+3+8
 * @param string $open_result_str 开奖结果,类似 4+15+20+25+26+2+8
 * @return array
 */
function countDltLottery($buy_str, $open_result_str) {
    $result = [
        'win_ammount' => 0,//中奖金额
        'lottery_level' => ''//中奖等级描述
    ];

    $buy_list = explode('+', $buy_str);
    $buy_red_list = array_splice($buy_list, 0, 5);
    array_walk($buy_red_list, function (&$value) {
        $value = intval($value);
    });
    $buy_blue_list = array_splice($buy_list, -2);
    array_walk($buy_blue_list, function (&$value) {
        $value = intval($value);
    });

    $open_result_list = explode('+', $open_result_str);
    $open_result_red_list = array_splice($open_result_list, 0, 5);
    array_walk($open_result_red_list, function (&$value) {
        $value = intval($value);
    });
    $open_result_blue_list = array_splice($open_result_list, -2);
    array_walk($open_result_blue_list, function (&$value) {
        $value = intval($value);
    });

    $red_lottery_num = count(array_intersect($buy_red_list, $open_result_red_list));
    $blue_lottery_num = count(array_intersect($buy_blue_list, $open_result_blue_list));

    if ($blue_lottery_num == 2) {
        switch ($red_lottery_num) {
            case 0:
            case 1:
                $result['win_ammount'] = 5;
                $result['lottery_level'] = '九等奖';
                break;
            case 2:
                $result['win_ammount'] = 15;
                $result['lottery_level'] = '八等奖';
                break;
            case 3:
                $result['win_ammount'] = 200;
                $result['lottery_level'] = '六等奖';
                break;
            case 4:
                $result['win_ammount'] = 3000;
                $result['lottery_level'] = '四等奖';
                break;
            case 5:
                $result['win_ammount'] = 10000000;
                $result['lottery_level'] = '一等奖';
                break;
        }
    } else if ($blue_lottery_num == 1) {
        switch ($red_lottery_num) {
            case 0:
            case 1:
                break;
            case 2:
                $result['win_ammount'] = 5;
                $result['lottery_level'] = '九等奖';
                break;
            case 3:
                $result['win_ammount'] = 15;
                $result['lottery_level'] = '八等奖';
                break;
            case 4:
                $result['win_ammount'] = 300;
                $result['lottery_level'] = '五等奖';
                break;
            case 5:
                $result['win_ammount'] = 5000000;
                $result['lottery_level'] = '二等奖';
                break;
        }
    } else {
        switch ($red_lottery_num) {
            case 0:
            case 1:
            case 2:
                break;
            case 3:
                $result['win_ammount'] = 5;
                $result['lottery_level'] = '九等奖';
                break;
            case 4:
                $result['win_ammount'] = 100;
                $result['lottery_level'] = '七等奖';
                break;
            case 5:
                $result['win_ammount'] = 10000;
                $result['lottery_level'] = '三等奖';
                break;
        }
    }

    return $result;
}

标签: php php教程

热门推荐