http://git.oschina.net/qiawei/qwadminphp
App/Qwadmin/Controller/ComController.class.phpgit
protected function getMenu($items,$id='id',$pid='pid',$son = 'children'){ $tree = array(); $tmpMap = array(); $father_ids = array(); //修復父類設置islink=0,可是子類仍然顯示的bug by shaoneng foreach( $items as $item ){ if( $item['pid']==0 ){ $father_ids[] = $item['id']; } } //---- foreach ($items as $item) { $tmpMap[$item[$id]] = $item; } foreach ($items as $item) { //修復父類設置islink=0,可是子類仍然顯示的bug by shaoneng if( $item['pid']<>0 && !in_array( $item['pid'], $father_ids )){ continue; } //---- if (isset($tmpMap[$item[$pid]])) { $tmpMap[$item[$pid]][$son][] = &$tmpMap[$item[$id]]; } else { $tree[] = &$tmpMap[$item[$id]]; } } return $tree; }