<?PHP/** * Recursive method to achieve infinite level classification * @param array $list to generate a tree list of arrays [must have primary key ID and parent PID in the array] * @param int $pid = 0 Parent ID * @param int $level = 0 indent [To specify the number of class names to indent]*/functionGettree ($list,$pid=0,$level=0 ) { //Static indicates that a static variable is declared, and that its value is persisted in the function . Static $tree=Array(); foreach($list as $row) { if($row[' PID ']==$pid) { //This level is not in the original array and is used to indicate the number of indents $row[' level '] =$level; $tree[] =$row; //recursive operation, re-passing the current ID into the function, get the sub-category of the current ID correspondingGettree ($list,$row[' ID '],$level+ 1); } } return $tree;}
Php_ Recursive implementation of infinite class classification