PHP unlimited classification, PHP Classification

Source: Internet
Author: User

PHP unlimited classification, PHP Classification

I haven't used infinitus classification for a while. Unfortunately, I used it again today, so I went to review it before. In order to avoid future troubles, we will post it here.

<? Php/*** unlimited classification class */class Category {/*** returns a one-dimensional array * @ param [type] $ the array to be recursive by cate * @ param string $ html Sub-Level indentation to be displayed before classification. Default Value: '-' * @ param integer $ pid parent category ID. The default value is 0, indicating the top-level category * @ param integer $ level. With $ html, sufficient indentation is displayed. The default value is 1, indicating top-level classification * @ return [type] [description] */static public function unlimitedForLevel ($ cate, $ html = '-', $ pid = 0, $ level = 1) {$ arr = array (); foreach ($ cate as $ v) {if ($ v ['pid '] = $ pid) {$ v ['level'] = $ level; $ v ['html'] = str_repeat ($ html, $ level-1); $ arr [] = $ v; $ arr = array_merge ($ arr, $ this-> unlimitedForLevel ($ cate, $ html, $ v ['id'], $ level + 1 ));}} return $ arr;}/*** returns a multi-dimensional array * @ param [Type] $ cate the array to be recursive * @ param string $ name the key * @ param integer $ pid of the subcategory in the parent category array. The default value is 0, indicating the top-level category * @ return [type] [description] */static public function unlimitedForlayer ($ cate, $ name = 'child ', $ pid = 0) {$ arr = array (); foreach ($ cate as $ v) {if ($ v ['pid '] = $ pid) {$ v [$ name] = self: unlimitedForlayer ($ cate, $ name, $ v ['id']); $ arr [] = $ v ;}} return $ arr ;} /*** pass the subcategory ID to return all parent classes * @ param [type] $ cate the array to be recursive * @ param [type] $ id subcategory ID * @ return [type] [description] */static public Function getParents ($ cate, $ id) {$ arr = array (); foreach ($ cate as $ v) {if ($ v ['id'] = $ id) {$ arr [] = $ v; $ arr = array_merge (self: getParents ($ cate, $ v ['pid ']), $ arr );}} return $ arr ;} /*** pass the parent category ID to return all sub-category IDs * @ param [type] $ the array to be recursive by cate * @ param [type] $ pid parent category ID *@ return [type] [description] */static public function getChildrenId ($ cate, $ pid) {$ arr = array (); foreach ($ cate as $ v) {if ($ v ['Pi D'] ==$ pid) {$ arr [] = $ v ['id']; $ arr = array_merge ($ arr, self: getChildrenId ($ cate, $ v ['id']) ;}return $ arr ;} /*** pass the parent category ID to return all subcategories * @ param [type] $ the array to be recursive by cate * @ param [type] $ pid parent category ID *@ return [type] [description] */static public function getChildren ($ cate, $ pid) {$ arr = array (); foreach ($ cate as $ v) {if ($ v ['pid '] = $ pid) {$ arr [] = $ v; $ arr = array_merge ($ arr, self: getChildren ($ cat E, $ v ['id']) ;}return $ arr ;}}?>

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.