/**
* 测试随机算法
* 总7题,随机出3题
* @param Request $request
*/
public function ceshi(Request $request){
//章节题列表
$zjans =DB::table('articles')
->where('category_id',6)
->select(['id'])
->get()
->toArray();
//循环遍历
foreach ($zjans as $k => $v){
$zjans[$k] = $v->id;
}
//数组函数array_flip()键值对换位置
$aa = array_flip($zjans);
//随机抽取3道题
$bb = array_rand($aa,3);
$chazj = DB::table('articles')
->whereIn('id',$bb)
->get()
->toArray();
dump($chazj);die;
}