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!