Method Code:
Static Public functionUnlimitedforlayer ($data,$pid=0){ $arr=Array(); foreach($data as $v) { if($v[' PID ']==$pid) { $v[' Child ']=self::unlimitedforlayer ($data,$v[' ID ']); $arr[]=$v; } } return $arr; }
Calling program:
<?phpnamespace Home\controller; UseThink\controller; Usehome\clas\cate;classIndexcontrollerextendsController { Public functionindex () {$data=Array( ' 0 ' + =Array( ' id ' =>1, ' pid ' =>0 ), ' 1 ' + =Array( ' id ' =>2, ' pid ' =>0 ), ' 2 ' + =Array( ' id ' =>3, ' pid ' =>1 ), ' 3 ' + =Array( ' id ' =>4, ' pid ' =>3 ) ); //$data =cate::unlimitedforlevel ($data); $data=cate::unlimitedforlayer ($data); Echo' <pre> '; Print_r($data); die; Echo' </pre> '; $this-display (); }}
:
Infinite pole classification, which presses a subset array below a subkey of the parent set array for a better loop display in the foreground template