$shopObj = new ShopModel();
$this->data = $shopObj->field('id')->select();
//二维数组降一维
$this->data = $this->translatArray2($this->data);
//一维数组打算顺序
shuffle($this->data);
//长度4分割数组
$this->data = array_chunk($this->data,4);
//查出随机的店铺
$this->data = $shopObj->alias('a')->field($this->Lfield)
->join('wd_yylm_shop_attr b','a.id = b.shopid','left')
->where('a.id','in',$this->data[$p-1])
->select();//查出的二维数组下标是分页P,用In方法查出4个数据
if (empty($this->data)) {
$this->msg = '数据为空';
}
shuffle(),将一维数组打乱顺序,成功返回1,失败返回0;
array_chunk($arr,$num),可以将一维数组$arr长度4个为一组,分割成若干个小数组
来源:https://www.cnblogs.com/hanshuai0921/p/6547780.html