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; }