PHP随机读取取出数据库表的数据返回数组
/** * 随机获取数据 * @param string $num 抽取条数 * @param string $table 表名 * @param string $where 查询条件 * @return array */ function tt_random_data($num,$table,$where=[]) { $countcus = $this->db->table($table)->where($where)->lists();//查询数据 shuffle($countcus); //打乱数组 $new_ary = array_slice($countcus,0,$num); //抽取数据 return $new_ary; }
相关文档
上一篇:没有了