//分类数大于4的都放到其他分类下
$where ="is_deleted=1 and is_open=1 and concat(path,'/') like '".$cate_id."/%' and type_id !=0"; $cate_info=$store_goods_category->field('id,name,path,sort')->where($where)->order('sort desc')->select();$i=0; $cn=count($cate_info); if($cn > 1){$cate_info[]=array('id'=>0,'name'=>'全部','sort'=>10000000,); } //取得列的列表 $ids=array(); foreach ($cate_info as $k4 => $v4){$ids[$k4] = $v4['sort']; } array_multisort($ids, SORT_DESC,$cate_info); $cate=array(); $cate_child=array(); $cates=array(); foreach($cate_info as $k2=>$v2){$i++;if($cn >= 5){if($i>=5){$cate_child[]=array('id'=>$v2['id'],'name'=>$v2['name'],'sort'=>$v2['sort'],);}else{$cate[]=array('id'=>$v2['id'],'name'=>$v2['name'],'sort'=>$v2['sort'],);}}else{$cate[]=array('id'=>$v2['id'],'name'=>$v2['name'],'sort'=>$v2['sort'],);} } if($cn >= 5){$cates[]=array('id'=>"",'name'=>"其他分类",'child'=>$cate_child);$cate_info3=array_merge($cate,$cates); }else{$cate_info3=$cate; }
转载于:https://www.cnblogs.com/zouke1220/p/8242200.html