- <?php
-
- /*
- * Find sub-columns
- */
-
- $area=array(
- Array(' id'=>1,' name '='China ' ,' parent '=>0),
- Array(' id'=>2,' name '='Guangdong ' ,' parent '=>1),
- Array(' id '=>3,' name '='shenzhen ', ' Parent ' =>2),
- Array(' id'=>4,' name '='Hunan ' ,' parent '=>1),
- Array(' id'=>5,' name '='Changsha ' ,' parent '=>4)
- );
-
- function findson ($arr,$id=0) {
- $son=array();
- foreach ( $arr as $value) {
- if ($value[' parent ']==$id ) {
- $son[]=$value;
- }
- }
- return $son;
- }
-
- /*
- * Find a descendant tree
- * @param array passed in by array
- * @param int ID passed in
- */
-
- function substree ($arr,$id=0,$level =1) {
- static $grandson=array();
-
- foreach ( $arr as $value) {
- if ($value[' parent ']==$id ) {
- $value[' level ']=$level;
- $grandson[]=$value;
- Substree ($arr,$value[' id '],$level +1);
- }
- }
- return $grandson;
- }
-
- //var_dump (Findson ($area, 1));
- echo "</br>";
- //var_dump (Substree ($area, 2));
-
- /*
- * In order for it to show indentation effect
- */
- $tt=substree ($area, 0, 1);
-
- foreach ( $tt as $value) {
- echo str_repeat (", $value [" Level "]). $value ["name"]. "</br>" ;
- }
-
- ?>
Recursive sub-columns in Simple infinite classification