«

php计算双色球中奖金额方法

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


php计算双色球中奖金额方法。

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

    $buy_list = explode('+', $buy_str);
    $buy_red_list = array_splice($buy_list, 0, 6);
    array_walk($buy_red_list, function (&$value) {
        $value = intval($value);
    });
    $buy_blue_list = [intval(end($buy_list))];

    $open_result_list = explode('+', $open_result_str);
    $open_result_red_list = array_splice($open_result_list, 0, 6);
    array_walk($open_result_red_list, function (&$value) {
        $value = intval($value);
    });
    $open_result_blue_list = [intval(end($open_result_list))];

    $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) {
        switch ($red_lottery_num) {
            case 0:
            case 1:
            case 2:
                $result['win_ammount'] = 5;
                $result['lottery_level'] = '六等奖';
                break;
            case 3:
                $result['win_ammount'] = 10;
                $result['lottery_level'] = '五等奖';
                break;
            case 4:
                $result['win_ammount'] = 200;
                $result['lottery_level'] = '四等奖';
                break;
            case 5:
                $result['win_ammount'] = 3000;
                $result['lottery_level'] = '三等奖';
                break;
            case 6:
                $result['win_ammount'] = 5000000;
                $result['lottery_level'] = '一等奖';
                break;
        }
    } else {
        switch ($red_lottery_num) {
            case 0:
            case 1:
            case 2:
            case 3:
                $result['win_ammount'] = 0;
                $result['lottery_level'] = '六等奖';
                break;
            case 4:
                $result['win_ammount'] = 10;
                $result['lottery_level'] = '五等奖';
                break;
            case 5:
                $result['win_ammount'] = 200;
                $result['lottery_level'] = '四等奖';
                break;
            case 6:
                $result['win_ammount'] = 100000;
                $result['lottery_level'] = '二等奖';
                break;
        }
    }

    return $result;
}

标签: php php教程

热门推荐