码迷,mamicode.com
首页 > 其他好文 > 详细

考试系统随机出题处理逻辑

时间:2018-11-22 20:46:27      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:his   diff   err   func   ret   private   stat   bsp   ase   

 /*
     * 随机处理逻辑
     * */
    private function _Rand($type, $num){
        if (intval($num) <= 0){ return false;}
        $problemArr = ProblemModel::getBaseArr([‘state‘ => 1, ‘type‘ => $type], [‘id‘], [], [‘order‘ => SORT_DESC]);
        $problemArr = array_column($problemArr, ‘id‘);

        $PaperArr = PaperProblemModel::getBaseArr([‘type‘ => $type], [‘problem_id‘]);
        $PaperArr = array_column($PaperArr, ‘problem_id‘);

        $d_count = count($problemArr);
        if ($d_count < $num) { $this->_error(‘数据表选题数量不够‘, []);}

        $Arr = array_diff($problemArr, $PaperArr);
        $count = count($Arr);
        if ($count < $num){
            $return = array_rand($problemArr, $num);
        } else {
            $problemArr = array_unique($Arr);
            $return = array_rand($problemArr, $num);
        }
        $res = [];
        foreach ($return  as $k => $v){
            $res[$k] = $problemArr[$return[$k]];
        }
        return $res;
    }

 

考试系统随机出题处理逻辑

标签:his   diff   err   func   ret   private   stat   bsp   ase   

原文地址:https://www.cnblogs.com/ghjbk/p/10003293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!