PHP two methods to implement stepless recursive classification, php two methods of Stepless Recursion

Source: Internet
Author: User

PHP two methods to implement stepless recursive classification, php two methods of Stepless Recursion

For more information, see the code:

/*** Stepless recursive classification TP framework * @ param int $ assortPid parent id of the category to be queried * @ param mixed $ delimiter between the upper and lower levels of the tag * @ return string $ tree returned classification Tree Structure result **/function recursiveAssort ($ assortPid, $ tag = '') {$ assort = M ('goods _ class')-> where (" class_pid = $ assortPid ")-> field ('class _ id, class_name ')-> select (); foreach ($ assort as $ value) {$ tree. = '<option value = "'. $ value ['class _ id']. '"> '. $ tag. $ value ['class _ name']. '</option>'; $ tree. = recursiveAssort ($ value ['class _ id'], $ tag. 'category');} return $ tree ;}
/*** Use php reference to pass the CI framework **/public function get_access () {$ access = array (); $ field = 'id, pid, method, name, description '; $ q_access = $ this-> db-> select ($ field)-> get ('access'); $ q_result = $ q_access-> result_array (); if (! Empty ($ q_result) {$ items = array (); foreach ($ q_result as $ value) {$ items [$ value ['id'] = $ value ;} foreach ($ items as $ key => $ item) {if ($ item ['pid '] = 0) {$ access [] = & $ items [$ key];} else {$ items [$ item ['pid '] ['sub _ access'] [] = & $ items [$ key] ;}} return $ access ;}

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

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.