thinkphp里面的无限级分类
程序员文章站
2022-05-23 15:52:42
...
php代码
<?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; } } ?>
上一篇: 网站代码最后被加上其他代码,是咋回事
下一篇: php怎么获取图片的高度和宽度?