首页 > 代码库 > 一维数组打乱顺序shuffle函数

一维数组打乱顺序shuffle函数

 $shopObj    = new ShopModel();
            $this->data = http://www.mamicode.com/$shopObj->field(‘id‘)->select();
            //二维数组降一维
            $this->data = http://www.mamicode.com/$this->translatArray2($this->data);
            //一维数组打算顺序
            shuffle($this->data);
            //长度4分割数组
             $this->data = http://www.mamicode.com/array_chunk($this->data,4);
             //查出随机的店铺
             $this->data = http://www.mamicode.com/$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();
             if (empty($this->data)) {
                 $this->msg = ‘数据为空‘;
             }

shuffle(),将一维数组打乱顺序,成功返回1,失败返回0;

array_chunk($arr,$num),可以将一维数组$arr长度4个为一组,分割成若干个小数组

一维数组打乱顺序shuffle函数