CI框架层级分类

public function shop_allot(){
    $arr = $this->db->get('ecs_category')->result_array();
    //调用list_level方法
    $str['i'] = $this->list_level($arr, $parent_id = 0, $level = 0);
    $this->load->view('shop/shop_allot', $str);
}


public function list_level($arr, $parent_id = 0, $level = 0){
    static $data = array();
    foreach ($arr as $v) {
        if ($v['parent_id'] == $parent_id) {
            $v['level'] = $level;
            $data[] = $v;
            $this->list_level($arr, $v['cat_id'], $level + 1);
        }
    }
    return $data;
}

你可能感兴趣的:(CI框架层级分类)