美文网首页程序员
tp5随机抽取一条或多条

tp5随机抽取一条或多条

作者: 牛逼_5596 | 来源:发表于2019-03-07 21:50 被阅读0次

我这里用的是thinkcmf5 column,toArray,这些是框架自带的函数

```

<?php

//多条

//取出red_prize的ID并转成一维数组

  $list = Db::name('red_prize')->column('id');

  //  $list = Db::name('red_prize')->select();

  //$list = array_column($list,'id');

        $rand_list = array_rand($list,3);//随机抽取3条

        $tuijian_array = array();

        foreach ((array)$rand_list as $key) {

            $tuijian_array[] = $list[$key];

        }

        $randArr = Db::name('red_prize')->where('id','in',$rand_list)->select()->toArray();

```

相关文章

网友评论

    本文标题:tp5随机抽取一条或多条

    本文链接:https://www.haomeiwen.com/subject/ujkkpqtx.html