PHP父菜单包含子菜单方式
private function getTree($data, $pid = 0) { $tree = []; foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $v['children'] = $this->getTree($data, $v['id']); $tree[] = $v; unset($data[$k]); } } return $tree; }
PHP清除缓存代码
if(!function_exists('delete_dir_file')){ function delete_dir_file($dir){ if(is_dir($dir)){ $handle = opendir($dir); while(($item = readdir($handle)) !== false){ if($item != '.' && $item != '..'){ if(is_dir($dir.'\\'.$item)){ delete_dir_file($dir.'\\'.$item); }else{ unlink($dir.'\\'.$item); } } } } closedir($handle); }}
PHP封装登录跳转代码
//封装登录欺骗跳转函数function jumpTo($url){ echo "<script type='text/javascript'>"; //完整地址 echo "location.href='" . $url . "'"; echo "</script>";}
PHP无限级分类阶梯菜单
// 无限级分类 阶梯菜单 static public function RuleList($rule,$pid=0,$lev=1){ $arr=array(); foreach($rule as $v){ if($v['pid']==$pid){ $v['lev']=$lev; $arr[]=$v; $arr=array_merge($arr,self::RuleList($rule,$v['id'],$lev+1)); } } return $arr; }