ram4nd Posted March 20, 2010 Share Posted March 20, 2010 I have this code: function get_tutorial_categories($category_id, $seperator, $selected = false, $link = true) { $CI = get_instance(); static $category, $up_category; $category = $CI->categories_model->get_category($category_id); $up_category = $CI->categories_model->get_category($category->parent_id); if(empty($up_category->parent_id)) return $category->name; else return $category->name.$seperator.get_tutorial_categories($category->parent_id, $seperator, $selected, $link); } I need to do: return get_tutorial_categories($category->parent_id, $seperator, $selected, $link).$category->name.$seperator; instad of the last line, but $category is the value of the last round of this recursive function. Quote Link to comment Share on other sites More sharing options...
ram4nd Posted March 21, 2010 Author Share Posted March 21, 2010 Solved it function get_tutorial_categories($category_id, $seperator) { $CI = get_instance(); static $category, $up_category, $links_array; //get category $category = $CI->categories_model->get_category($category_id); //get upper level category $up_category = $CI->categories_model->get_category($category->parent_id); //push $links_array[] = $category->name; //if upper category parent_id is 0, return category name if(empty($up_category->parent_id)) { return array_shift($links_array); } //if upper category parent_id isn't 0, return get_main_category($category->parent_id) else { return get_tutorial_categories($category->parent_id, $seperator, $selected, $link).' '.$seperator.' '.array_shift($links_array); } } Quote Link to comment Share on other sites More sharing options...
ram4nd Posted March 21, 2010 Author Share Posted March 21, 2010 Dang, edit button gone, if anyone wants to use the code then use array_pop not array shift Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.