Date: 05/16/06 (PHP Community) Keywords: no keywords basically i've written some code that will apply a child array to a parent array so it looks like this Array ( [1] => Array ( [commentid] => 1 [entryid] => 10 [parentid] => 0 [userid] => 10 [child] => ) [2] => Array ( [commentid] => 2 [entryid] => 10 [parentid] => 0 [userid] => 10 [child] => Array ( [4] => Array ( [commentid] => 4 [entryid] => 10 [parentid] => 2 [userid] => 10 [child] => ) ) ) [3] => Array ( [commentid] => 3 [entryid] => 10 [parentid] => 0 [userid] => 10 [child] => ) [5] => Array ( [commentid] => 5 [entryid] => 10 [parentid] => 0 [userid] => 10 [child] => ) ) however the problem i have is that i can't get it to go any deeper than a second array in. i've been racking my head to think of a way to get the code to recur upon itself, however i can't think of a methodology for that (this is inside a while). if (!empty($comment['parentid'])) { if (array_key_exists($comment['parentid'], $this->temp->comment)) { $this->temp->comment[$comment['parentid']]['child'][$comment['commentid']] = create_comment($comment); } } else { $this->temp->comment[$comment['commentid']] = create_comment($comment); } can anyone help me out as i'm totally lost now. oh the create_comment() function is one of sheer simplicity function create_comment($comment) { return array( 'commentid' => $comment['commentid'], 'journalid' => $comment['journalid'], 'entryid' => $comment['entryid'], 'parentid' => $comment['parentid'], 'userid' => $comment['userid'], 'username' => $comment['username'], 'title' => $comment['title'], 'pagetext' => $comment['pagetext'], 'dateline' => $comment['dateline'], 'usericon' => ($comment['usericon']) ? $comment['usericon'] : $comment['defaultusericon'], 'screened' => $comment['screened'], 'child' => '' ); } anyhelp would be very much appreciated.
|