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. Link to comment https://forums.phpfreaks.com/topic/195903-recursive-function-problem/ 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); } } Link to comment https://forums.phpfreaks.com/topic/195903-recursive-function-problem/#findComment-1029633 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 Link to comment https://forums.phpfreaks.com/topic/195903-recursive-function-problem/#findComment-1029641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.