php将从数据库取出的数据分为6个一组的二维数组

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZNYSYS520/article/details/82799020

$presell = M('presell')->field('id,sname,num,weight,shop_price,endtime,supply,givetime')->where($info)->order('id desc')->select();
        //将数据分为6个一组的二维数组
        rsort($presell);
        $newArr = [];
        while(!empty($presell)) {
            $count = 6;
            $tmpArr = [];
            for($i = 0; $i< $count ; $i++) {
                $tmpArr[] = array_pop($presell);
            }
            $newArr[] = $tmpArr;
        }
        foreach ($newArr as $key => $value) {
            foreach ($value as $k => $val) {
                if(empty($val)){
                    unset($newArr[$key][$k]);
                }
            }
        }
        $this->assign('presell',$newArr);

猜你喜欢

转载自blog.csdn.net/ZNYSYS520/article/details/82799020