php无线分类按子分类排序
作者:互联网
//把所有栏目id返回 //$cateRes为$cateRes = db('StoreClass')->where('store_id',$uid)->order('class_sort desc')->select(); public function catetree($cateRes){ return $this->sort($cateRes); } public function sort($cateRes,$pid=0,$level=0){ static $arr=array(); foreach ($cateRes as $k => $v) { if($v['class_pid']==$pid){ $v['level']=$level; $arr[]=$v; $this->sort($cateRes,$v['class_id'],$level+1); } } return $arr; } //获取子栏目的id //$cateid为要查询的id public function childrenids($cateid){ $data =db('StoreClass')->field('class_id,class_pid')->select(); return $this->_childrenids($data,$cateid); } private function _childrenids($data,$cateid){ static $arr = array(); foreach ($data as $k => $v) { if($v['class_pid']==$cateid){ $arr[] = $v['class_id']; $this->_childrenids($data,$v['class_id']); } } return $arr; }
标签:arr,按子,分类,pid,class,cateRes,php,cateid,id 来源: https://www.cnblogs.com/seanpan/p/13993306.html