zoukankan      html  css  js  c++  java
  • 无限极分类之查找子孙树

     1 <?php
     2 
     3 header('content-type:text/html;charset=utf8');
     4 $area = array(
     5 array('id'=>1,'name'=>'安徽','parent'=>0),
     6 array('id'=>2,'name'=>'海淀','parent'=>7),
     7 array('id'=>3,'name'=>'濉溪县','parent'=>5),
     8 array('id'=>4,'name'=>'昌平','parent'=>7),
     9 array('id'=>5,'name'=>'淮北','parent'=>1),
    10 array('id'=>6,'name'=>'朝阳','parent'=>7),
    11 array('id'=>7,'name'=>'北京','parent'=>0),
    12 array('id'=>8,'name'=>'上地','parent'=>2)
    13 );
    14 
    15 
    1
    31 
    32 function subtree($arr,$id=0){//$id 默认从0开始
    33      static $subs = array();  //静态属性只指向一个地址,不会每次引用都清空$subs;
    34 
    35     foreach($arr as $v){
          //$v 是子数组
    36 if($v['parent'] == $id){
              //$subs 是空数组
    37 $subs[] = $v; 38 subtree($arr,$v['id']);// 39 } 40 } 41 return $subs; 42 } 43 print_r(subtree($area,0)); 44 ?>

    static 总结

    1:修饰类的属性和方法,静态属性,静态方法;

    2:延迟绑定;static::method();

    3:在函数中、方法中声明静态变量用

  • 相关阅读:
    Java.io.outputstream.PrintStream:打印流
    Codeforces 732F. Tourist Reform (Tarjan缩点)
    退役了
    POJ 3281 Dining (最大流)
    Light oj 1233
    Light oj 1125
    HDU 5521 Meeting (最短路)
    Light oj 1095
    Light oj 1044
    HDU 3549 Flow Problem (dinic模版 && isap模版)
  • 原文地址:https://www.cnblogs.com/a2762/p/4026562.html
Copyright © 2011-2022 走看看