/** * Convert the returned data set to tree * @param array $list DataSet to convert * @param string $pid parent Tag field * @param string $level level tag field * @re Turn array * @author mai when fuel <[email protected]>*/functionList_to_tree ($list,$PK= ' id ',$pid= ' pid ',$child= ' _child ',$root= 0) { //Create Tree $tree=Array(); if(Is_array($list)) { //creating an array reference based on a primary key $refer=Array(); foreach($list as $key=$data) { $refer[$data[$PK]] =&$list[$key]; } foreach($list as $key=$data) { //determine if there is a parent $parentId=$data[$pid]; if($root==$parentId) { $tree[] =&$list[$key]; }Else{ if(isset($refer[$parentId])) { $parent=&$refer[$parentId]; $parent[$child[] =&$list[$key]; } } } } return $tree;}/** * Restore List_to_tree tree to list * @param array $tree The original tree * @param string $child The key of the child node * @param string er Sort the displayed key, is generally The primary key is arranged in ascending order * @param array $list the intermediate array for the transition, * @return Array returns an ordered list of arrays * @author Yangweijie <[email protected]> */functionTree_to_list ($tree,$child= ' _child ',er= ' id ', &$list=Array()){ if(Is_array($tree)) { $refer=Array(); foreach($tree as $key=$value) { $reffer=$value; if(isset($reffer[$child])){ unset($reffer[$child]); Tree_to_list ($value[$child],$child,er,$list); } $list[] =$reffer; } $list= List_sort_by ($list,er,$sortby= ' ASC '); } return $list;}
The method of infinite classification data processing