Hello Guys,
I need a little bit of help with recursion. I've searched our PHP website and Google, but none helped me understand my problem. There is a code below this message in order to help you understand what I am trying to achieve. Here is an explaination:
What I'm trying to do is list a typical category/subcategory system with parents and children associated with those parents. My database table (categories) lists all the parents and children together, each with a parent_id field (with root being a value of 0). What I want to do is, if a user clicked on one of the parent categories, only one level of that category will show (or only the direct children of that specific category will show). I want the depth to be endless because I want to control the depth some other way. I know that using a recursive theory would cost a lot as far as speed goes, but I'm willing to risk it for now.
Here is the problem: The problem is that the recursive method yields several arrays, instead of one long array. I tried to use an array_push() function, but that doesn't seem to work well with multi-dimentional arrays. I tried the straight way, i.e. $menu_array[$count]['name'] = $name_of_category or $menu_array['name'][$count] = $name_of_category, but that yields several arrays instead of one long array or category names. The depth of the categories can be determined by the $_GET string passed, $_GET['some_path'], which is in the format: parent1_child1_grandchild1_grandchild2, etc.($some_path = 1_4_6_8), where all of these are related to each other. These, of course, are split using the underscore delimeter: $path['0'] = 1, $path['1'] = 4, and so on.
Can you give a sample of what the print_r() of the desired output would be like? That would help :)
-- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com ----------------------- "Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing."
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php