recursive function to get all the child categories

后端 未结 7 860
时光取名叫无心
时光取名叫无心 2020-12-03 03:54

Here is what I\'m trying to do: - i need a function that when passed as an argument an ID (for a category of things) will provide all the subcategories and the sub-sub categ

7条回答
  •  醉酒成梦
    2020-12-03 04:22

    Using Prestashop function :

    public function getRecursiveChildren() {
    
        $subCategories = $this->recurseLiteCategTree();
        //print_r($subCategories);
    
    
        $my_tab = array();
    
        foreach ($subCategories['children'] as $subc) {
            $my_tab[]   = $subc['id'];
            foreach ($subc['children'] as $subc2) {
                $my_tab[]   = $subc2['id'];
                foreach ($subc2['children'] as $subc3) {
                    $my_tab[]   = $subc3['id'];
                    foreach ($subc3['children'] as $subc4) {
                        $my_tab[]   = $subc4['id'];
                    }
                }
            }
        }
        $my_tab [] = $this->id; 
    
        return $my_tab;
    }
    

    this can be ameliorated using recursivity but no time for that today :'(

提交回复
热议问题