search
Homephp教程php手册最高效的无限级菜单生成方法

最高效的无限级菜单生成方法
$Menu= M('Menu');<br> $items= $Menu->order('pid, sort')->select();//按pid从小到大排序,以保证父节点在前,子节点在后。sort是同一层次节点的显示顺序。<br> $menu = array();<br> foreach ($items as $v) {<br>     $menu[$v['_id']] = $v;<br>     $menu[$v['_id']]['items'] = array();//items存放当前节点的所有子节点。<br>     if($v['pid'] != 0) {<br>         $menu[$v['pid']]['items'][$v['_id']] = &$menu[$v['_id']];<br>     }<br> }<br> foreach ($menu as $k=>$v) {<br>     if($v['pid'] != 0) {<br>         unset($menu[$k]);<br>     }<br> }OT里面有对该功能的封装,目录位置Application\Common\Common\function.php文件里的list_to_tree函数,function.php文件里面还有很多功能函数大家可以看看。

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools