正文 473字数 343,004阅读


$num = 10;//几条数据 $count = Db::name( 'topic' )->count(); $rand = mt_rand( 0, $count-1 ); $limit = $rand.','.$count; $list = Db::name( 'topic' )->limit( $limit )->select(); shuffle( $list ); $new_ary = array_slice( $list, 0, $num );
Run code
Cut to clipboard


    $new_ary = Db::name('topic')->orderRaw('rand()')->limit(10)->select();
    Run code
    Cut to clipboard