// $res = Db::table('zx_article_6')->where('art_type_id',1)->orderRaw('rand()')->limit(10)->select();
// var_dump($res);
$ids = Db::table('zx_article_6')->where('art_type_id',1)->column('art_id');
shuffle($ids);
// $map[] = array('id'=>array('in', array_slice($ids, 0, 10)));//打乱并取出10个id
$map[] = ['art_id','in',array_slice($ids, 0, 10)];//打乱并取出10个id
$_result = Db::table('zx_article_6')->where('art_type_id',1)->where($map)->select()->toArray();
var_dump($_result);
用shuffle代替rand随机取出几条数据效率更高
最新推荐文章于 2021-08-28 21:01:50 发布