<?php
 
    Class Category{
 
        //一维数组无限级分类
        Static Public function yiwei($cate,$pid=0){
 
            $arr=array();
            foreach($cate as $v){
                if($v['pid'] == $pid){
                    $arr[]=$v;
                    $arr=array_merge($arr,self::yiwei($cate,$v['id']));
                }
                
            }
            return $arr;
        }
 
        //二位数组无限级分类
        Static Public function erwei($cate,$pid=0){
            $arr=array();
            foreach($cate as $v){
                if($v['pid'] == $pid){
                    
                    $v['child']=self::erwei($cate,$v['id']);
                    $arr[]=$v;
                }
            }
            return $arr;
        }
 
 
        //通过子级寻找父级
        Static Public function findFather($cate,$id){
            $arr=array();
            foreach($cate as $v){
                if($v['id'] == $id){
                    $arr[]=$v;
                    $arr=array_merge($arr,self::findFather($cate,$v['pid']));
                }
            }
            return $arr;
        }
 
        //通过父级寻找子级
        Static Public function findChild($cate,$pid){
            $arr=array();
            foreach($cate as $v){
                if($v['pid'] == $pid){
                    $arr[]=$v['id'];
                    $arr=array_merge($arr,self::findChild($cate,$v['id']));
                }
            }
            return $arr;
        }
    }
?>
 

稳定

产品可用性高于99.9%

贴心

全国7*24小时客服热线

专业

产品经理在线技术支持

快速

快速上线运营快

承诺

我们选择声誉

坚持

10年专注高端品质开发
  • 返回顶部