Insert separators in recursive output

There is a function:

function tree($id)
{
  //   
  while (...)
    {
       echo $result['name'];
       tree($result['id']);
    }
}
tree(0);

The result of the output is something like this:

Parent
->Children, Children, Children, Children
Parent
->Children, Children
Parent
->Children, Children, Children
//   N 

What mathematical function or expression should be added to add a sort of separator after every fifth one?


Answer 1, authority 100%

function tree($id, $n)
{
    if($n && !$n%5){
        // 
    }
    //   
    while (...)
    {
        echo $result['name'];
        tree($result['id'], $n+1);
    }
}

Answer 2

and if you enter a counter in while . for example i, and when it is equal to 5 – set it to zero and write a separator