<span style="color: #000000;">php </span><span style="color: #008080;">header</span>("Content-type: text/html; charset=utf-8"<span style="color: #000000;">); </span><span style="color: #800080;">$arr</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">( </span>0=><span style="color: #0000ff;">array</span>('Id'=>1,'Name'=>'文件管理','Pid'=>0), 1=><span style="color: #0000ff;">array</span>('Id'=>2,'Name'=>'来源管理','Pid'=>0), 2=><span style="color: #0000ff;">array</span>('Id'=>3,'Name'=>'文件添加','Pid'=>1), 3=><span style="color: #0000ff;">array</span>('Id'=>4,'Name'=>'文件删除','Pid'=>1), 4=><span style="color: #0000ff;">array</span>('Id'=>5,'Name'=>'人员列表','Pid'=>2), 5=><span style="color: #0000ff;">array</span>('Id'=>6,'Name'=>'添加用户','Pid'=>5), 6=><span style="color: #0000ff;">array</span>('Id'=>7,'Name'=>'编辑用户','Pid'=>5),<span style="color: #000000;"> ); </span><span style="color: #0000ff;">function</span> getTree(<span style="color: #800080;">$arr</span>, <span style="color: #800080;">$pid</span>=0,<span style="color: #800080;">$deep</span>=0<span style="color: #000000;">) { </span><span style="color: #0000ff;">static</span> <span style="color: #800080;">$tree</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">(); </span><span style="color: #0000ff;">foreach</span>(<span style="color: #800080;">$arr</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$k</span>=><span style="color: #800080;">$row</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">if</span>( <span style="color: #800080;">$row</span>['Pid'] == <span style="color: #800080;">$pid</span><span style="color: #000000;"> ) { </span><span style="color: #800080;">$row</span>['deep'] = <span style="color: #800080;">$deep</span><span style="color: #000000;">; </span><span style="color: #800080;">$tree</span>[] = <span style="color: #800080;">$row</span><span style="color: #000000;">; </span><span style="color: #0000ff;">unset</span>(<span style="color: #800080;">$arr</span>[<span style="color: #800080;">$k</span><span style="color: #000000;">]); getTree(</span><span style="color: #800080;">$arr</span>,<span style="color: #800080;">$row</span>['Id'],<span style="color: #800080;">$deep</span>+1<span style="color: #000000;">); } } </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$tree</span><span style="color: #000000;">; } </span><span style="color: #800080;">$res</span> = getTree(<span style="color: #800080;">$arr</span><span style="color: #000000;">); </span><span style="color: #0000ff;">echo</span> "<pre class="brush:php;toolbar:false">"<span style="color: #000000;">; </span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$res</span>);
运行结果:
Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

Video Face Swap
Tauschen Sie Gesichter in jedem Video mühelos mit unserem völlig kostenlosen KI-Gesichtstausch-Tool aus!

Heißer Artikel
Assassin's Creed Shadows: Seashell Riddle -Lösung
3 Wochen vorByDDD
Wo kann man die Kransteuerungsschlüsselkarten in Atomfall finden
3 Wochen vorByDDD
<🎜>: Dead Rails - wie man jede Herausforderung abschließt
4 Wochen vorByDDD
Atomfall Guide: Gegenstandsstandorte, Questführer und Tipps
1 Monate vorByDDD

Heiße Werkzeuge

Dreamweaver Mac
Visuelle Webentwicklungstools

VSCode Windows 64-Bit-Download
Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Sicherer Prüfungsbrowser
Safe Exam Browser ist eine sichere Browserumgebung für die sichere Teilnahme an Online-Prüfungen. Diese Software verwandelt jeden Computer in einen sicheren Arbeitsplatz. Es kontrolliert den Zugriff auf alle Dienstprogramme und verhindert, dass Schüler nicht autorisierte Ressourcen nutzen.

Dreamweaver CS6
Visuelle Webentwicklungstools
