Php unlimited Classification

Source: Internet
Author: User
A php unlimited classification method that I used a long time ago uses a recursive approach. Here I will share with you $ data is the classification data retrieved from the database, and $ pid is the parent classification id, $ level is the classification level, which is limited to 10. $ keyword is the classification name funvelgencate ($ data, $ pid0, $ level0, $ keyword) {if ($ level

A php unlimited classification method that has been used a long time ago adopts a recursive approach. Here we will share with you the // $ data for the classification data retrieved from the database, $ pid is the upper-level category id, $ level is the classification level, which is limited to 10 levels, $ keyword is the classification name function genCate ($ data, $ pid = 0, $ level = 0, $ keyword) {if ($ level =

A php unlimited classification method that I used a long time ago uses recursive methods. Here I will share it with you.

// $ Data is the classification data retrieved from the database, $ pid is the upper-level category id, $ level is the classification level, which is limited to 10, $ keyword is the classification name

Function genCate ($ data, $ pid = 0, $ level = 0, $ keyword) {if ($ level = 10) break; $ l = str_repeat ("", $ level); $ l = $ l. 'callback'; static $ arrcat = array (); $ arrcat = empty ($ level )? Array (): $ arrcat; foreach ($ data as $ k => $ row) {if ($ row ['pid '] = $ pid) {$ row [$ keyword] = $ l. $ row [$ keyword]; $ row ['level'] = $ level; $ arrcat [] = $ row; genCate ($ data, $ row ['id'], $ level + 1, $ keyword) ;}return $ arrcat ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.