Raliare Posted July 20, 2011 Share Posted July 20, 2011 I'm building a simple CMS system to learn more about PHP as work does not tax me. After much trial and error I've got a script working to collect children of children indefinitely and add them all into an array. My problem is I need to pass the array it's current location or else all new elements will be placed in the first array and not nested arrays for each child. The function is looking for all top level pages (first level pages have a parent Id of -1). then it runs its self going down branch level to find children of that element, then finding those children and so on. function test($parentID, $table_index='') { $child_arr = $this->query_database('', '', 'SELECT * FROM page WHERE parentID ='.$parentID); $count_children = count($child_arr); for($c=0; $c<$count_children; $c++) { $table_index .= '['.$c.']'; $this->page_list+$table_index = $child_arr[$c]['title']; $this->test($child_arr[$c]['ID'], $c); } print_r($this->page_list); //return $this->page_list; } The function is called and passed the top level parent id of "-1". It all works fine apart from $this->page_list+$table_index = $child_arr[$c]['title']; Just how do I construct and pass along my new location in the multidimensional array and pass this to the next iteration of the function so that the script knows where to insert the data? Or is there a better way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/242419-nested-functions-to-build-array/ Share on other sites More sharing options...
Guest MrLeN Posted July 20, 2011 Share Posted July 20, 2011 The only thing I can think of doing at this stage, is to detect the domain, ie: jack.mysite.com Get jack out, and use a header location to: www.mysite.com/jack That would be a compromise, but I don't want to compromise. I really want the account functioning with jack.mysite.com; sub pages as well as the index. This is really starting to irritate me! ARGH! It's getting close to wanting to destroy things with my face again. I think I might have to give up and try again in another 3 months, after I've forgotten how painful it was to do what one would think is a simple thing. Quote Link to comment https://forums.phpfreaks.com/topic/242419-nested-functions-to-build-array/#findComment-1245075 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.