Home php教程 php手册 php 无限级分类函数

php 无限级分类函数

Jun 13, 2016 am 11:23 AM
array e name php pid function Classification Millet unlimited Tree plant test apple food drinks

 

ar=array(0=>array('name'=>'食物','id'=>1,'pid'=>0), 

02               1=>array('name'=>'植物','id'=>2,'pid'=>0), 

03               3=>array('name'=>'白菜','id'=>3,'pid'=>1), 

04               4=>array('name'=>'树','id'=>4,'pid'=>2), 

05               5=>array('name'=>'苹果','id'=>5,'pid'=>3), 

06               6=>array('name'=>'松树','id'=>6,'pid'=>4), 

07               7=>array('name'=>'饮料','id'=>7,'pid'=>1), 

08               8=>array('name'=>'测试1','id'=>8,'pid'=>7), 

09               9=>array('name'=>'测试2','id'=>9,'pid'=>8), 

10               10=>array('name'=>'人民','id'=>10,'pid'=>9), 

11               11=>array('name'=>'小米','id'=>11,'pid'=>0), 

12               ); 

13   

14         echo '

'; 

15         tre($ar,0); 

16         echo '

'; 

17   

18         function tre($tree,$id) 

19         { 

20                 $str = ''; 

21                 $strid = ''; 

22                 foreach ($tree as $key => $item) 

23                 { 

24                         if ($item['pid'] == $id) { 

25                                 $i = 0; 

26                                 $i = sonNum($tree,$item['id']); 

27                                 if ($i == 1 || $i == 0) { 

28                                         echo '

'; 

29                                 } else { 

30                                         echo '

';         

31                                 } 

32                                 //echo '

'; 

33                                 echo $item['name']; 

34                                 echo '

'; 

35                                 tre($tree,$item['id']); 

36                         } 

37                 } 

38                 //tre($tree,$strid); 

39         } 

40           

41         function sonNum($tre,$sum,$totale=1) 

42         { 

43                 foreach ($tre as $key => $value) 

44                 { 

45                         if ($value['pid'] == $sum){ 

46                                 $totale += sonNum($tre,$value['id'],1); 

47                         } 

48                 } 

49                 return $totale; 

50         }


Statement of this Website
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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Download the official website of Ouyi Exchange app for Apple mobile phone Download the official website of Ouyi Exchange app for Apple mobile phone Apr 28, 2025 pm 06:57 PM

The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Apr 28, 2025 pm 07:51 PM

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Composer: Aiding PHP Development Through AI Composer: Aiding PHP Development Through AI Apr 29, 2025 am 12:27 AM

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

What is the significance of the session_start() function? What is the significance of the session_start() function? May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

Binance official website entrance Binance official latest entrance 2025 Binance official website entrance Binance official latest entrance 2025 Apr 28, 2025 pm 07:54 PM

Visit Binance official website and check HTTPS and green lock logos to avoid phishing websites, and official applications can also be accessed safely.

H5: Key Improvements in HTML5 H5: Key Improvements in HTML5 Apr 28, 2025 am 12:26 AM

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

How to use MySQL functions for data processing and calculation How to use MySQL functions for data processing and calculation Apr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

See all articles