多级下拉菜单

  
  
           
  
  
  1. /* 
  2.  * 权限分组目录树 
  3.  */ 
  4. public function getGroupTree(){ 
  5.     $data = $this->select(); 
  6.     $arrOptions = array(); 
  7.     $this->getOptions($data, 0, $arrOptions, 0); 
  8.     $strOptions = implode(''$arrOptions); 
  9.     return '<select name="user_role">'.$strOptions.'</select>'
  10.  
  11. private function getOptions($data$pid, &$arrOptions$level){ 
  12.     foreach ($data as $v){ 
  13.         if($v['pid']==$pid){ 
  14.             $arrOptions[] = $this->getHtmlOption($v['name'], $v['id'], $level); 
  15.             $this->getOptions($data$v['id'], $arrOptions$level+1); 
  16.         } 
  17.     } 
  18.  
  19.  
  20. private function getHtmlOption($name$id$level){ 
  21.     $pxValue = 10*$level
  22.     $option = '<option value="'.$id.'" style="padding-left: '.$pxValue.'px">' . $name . '</option>'
  23.     return $option