getChildCategories($category_id); } else { $categories = $this->getFirstLevelCategories(); } foreach ($categories as $category) { $data = array(); $data ["data"]["title"]= $category->title; $data ["data"]["attr"]["id"] = $category->id; $parent_childs = $this->getChildCategories($category->id); if (count($parent_childs) > 0) { $child_data = $this->getCategoriesAsArray($category->id); $data ["children"] = $child_data; } $result []= $data; } return $result; } } ?>