PHP real-life using recursive read product unlimited classification

Source: Internet
Author: User
Recently in a mall project, need to take out the data in the classification table, the classification table through a PID (parent class ID) associated with each classification, in order to organize the reading of the two-dimensional data into a tree-like format, the project has encapsulated the following method.

/** * [treecats description] * @param [Array] $arr [original unordered array] * @param [array] $limit [the first element represents Start recursive parent_id, default is 0, the second element represents the culling element and child element cat_id, if no value is passed, default is 0] * @param integer $level [depth of function call] * @return [ Array] [sorted arrays] * / Public functiontreecats($arr,$limit,$level=0) {$rec=Array();///Eliminate the value of cat_id firstforeach($arr as$key=$value){if($value[' cat_id ']!=$limit[' CD ']){$arr _new[$key]=$value; }        }//traverse the new arrayforeach($arr _new as$key=$value) {if($value[' parent_id ']==$limit["PD"] &&$value[' parent_id ']!=$limit["CD"]){$value[' Level ']=$level;$rec[]=$value;//Generate an array for the next layer of loops$next _limit=Array("PD"=$value[' cat_id '],"CD"=$limit["CD"]);$rec= Array_merge ($rec,$this->treecats ($arr,$next _limit,$level+1)); }        }return$rec; }

The scenario for setting up $limit here is that if you modify the parent classification of this classification to be its original sub-category, the taxonomy branch is lost, so it is time to remove its subclass from the optional class.

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the use of PHP real-life recursive reading products Unlimited classification, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.