首页 > 其他 > 详细

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

时间:2018-11-22 19:43:14      阅读:201      评论:0      收藏:0      [点我收藏+]
 /*
     * 随机处理逻辑
     * */
    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;
    }

 

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!