Implement infinitus classification-Recursive Implementation, implement unlimited classification Recursion
Public function getTree () {$ data = $ this-> select (); $ list = $ this-> _ getTreeData ($ data); return $ list ;} private function _ getTreeData ($ data = array (), $ parent_id = 0) {$ childs = $ this-> _ buildTree ($ data, $ parent_id ); // obtain all parent classes if (empty ($ childs) {return null;} foreach ($ childs as $ key => $ val) {$ rescurTree = $ this-> _ getTreeData ($ data, $ val ['id']); // recursively retrieve all subcategories under the current category if ($ rescurTree! = Null) {$ childs [$ key] ['childs '] = $ rescurTree;} return $ childs;} private function _ buildTree (& $ data, $ parent_id) {$ res = array (); foreach ($ data as $ key => $ val) {if ($ val ['parent _ id'] = $ parent_id) {$ res [] = $ val;} return $ res ;}