First the data table is similar to this, and then perform data query to obtain all the data
$sql ="select * from ec_admin_role where ar_state=1 order by ar_level"; $roles = $g_db->getAll($sql); $g_db->close(); $list=roletree($roles,0);//调用函数按父级id进行排序 foreach($list as $k=>$v) { $list[$k]['ar_name'] = str_repeat('----',$v['ar_level']).$v['ar_name'].'<br>'; } //将角色经排序 function roletree($arr,$id=0) { $subs = array(); // 子孙数组 foreach($arr as $v) { if($v['ar_parent_id'] == $id) { $subs[] = $v; $subs = array_merge($subs,roletree($arr,$v['ar_id'])); } } return $subs; }
Then the output is looped on the static page, the effect is as follows:
Whoever adds a subordinate to display the effect will have that subordinate next to him
The above is the detailed content of Introduction to Infinitus classification and sorting methods. For more information, please follow other related articles on the PHP Chinese website!