php 查找父类全部的子类

1.数据库表设计php

    id int(6) not null auto_increment primary keyhtml

    name varchar(20) not null ,数据库

    pid int(6),数组

    sort int (6)ui

 

2.php代码以下:spa

<?php设计

 

class category{code

 

   Static Public function parents_to_child($data,$pid=0,$level=0,$html='--'){htm

        

       $arr array();ci

       foreach($data as $v){

        

           if($v['pid'] == $pid){

               $v['level'] = $level+1;

               $v['html'] = str_repeat($html,$level);

               $arr[] = $v;

               $arr array_merge($arr,self::parents_to_child($data,$pid=$v['id'],$level=$level+1));

           }

        

       }

       return $arr;

   }

 

}

 

?>

3.在你须要分类的文件内载入类category,并引用静态方法

<?php

    require 'category.class.php';

     

    $cate = category::parents_to_child($data);

?>

如下代码是返回一个一维数组的无限分类

楼主能够根据本人所提供的代码根据本身的需求修改

相关文章
相关标签/搜索