Jump to content

[SOLVED] neverending function


miob

Recommended Posts

hi !

 

i have a big problem i have no clue how to code it. need to make a tree in function

 

i think i need to use same function in function, is that possible ?

 

 

example:

 

i have this working but only in 4 layers, i need to have it unlimited...

i can add next and next same thing over and over but i don't think it's good solution:

 

 

 

foreach ($forum_replies as $key => $replies){

if (!$replies[4])

{

listing($replies,'false');

 

foreach ($forum_replies as $key => $replies2){

  if ($replies2[4]==$replies[0]) {

  listing($replies2,'true');

foreach ($forum_replies as $key => $replies3){

  if ($replies3[4]==$replies2[0]) {

  listing($replies3,'true');

foreach ($forum_replies as $key => $replies4){

  if ($replies4[4]==$replies3[0]) {listing($replies4,'true'); ?></div><?}

}

  ?></div><?

  }

}

  ?></div><?

  }

}

?></div><?

}

}

 

Link to comment
https://forums.phpfreaks.com/topic/67246-solved-neverending-function/
Share on other sites

it looks like you want to use a recursive function that calls itself.

function recurseFunc($all_forum_replies) {
    foreach ($all_forum_replies as $key => $replies) {
        if (!$replies[4] || $replies[4] == $replies[0]) {
           listing($replies,'false');

           recurseFunc($replies);
        }
    }
}

 

call it once:

 

recurseFunc($forum_replies);

 

.... or similar

i don't wanna put URL's here...

 

forum_replies is array with posts in the forum

function listing will show up post from user.

 

something like this :

 

 

<div class="riadok1" style="height:50px; width:100%; repeat-x top; ">

<div class="autor" style="float:left; margin:3px; ">title: <b>Re: title of post</b><br>Author: miob, 28.08.07 - 02:46</div>

<div class="prisp" style="float:right; margin:3px;"><a href='?thread=5&reply=4#p4' name='p4'>Quote this post</a> </div>

</div>

<div style="clear: both;"></div>

<p style ="margin:3px;">text of the post</p>

 

 

and if there is no quote in the this post, i show "</div>"

 

i hope it's clear now

 

i managed to code it by myself, took me more hours but i'm glad i did it.

Anyway thank you guys i appreciate your help.

 

here is it if someone could need it ever:

 

function recurseFunc($all_forum_replies,$parent) {

    foreach ($all_forum_replies as $key => $replies) {

        if (($replies[4])&&($replies[4] == $parent)) {

          listing($replies,'true');

          recurseFunc($all_forum_replies,$replies[0]);

            ?></div><?

        }

    }

}

 

foreach ($forum_replies as $key =>  $replies){

if (!$replies[4]) { listing($replies,'false'); recurseFunc($forum_replies,$replies[0]);

?></div><?

  }

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.