Foreach inside foreach with parent elements, children and grandchildren

0

Good afternoon, gentlemen, I'm trying to print a paragraph dynamically but I'm having some difficulty.

I have the following code in html:

    form {} label {
      display: block
    }
    span {
      display: block;
      float: left;
      width: 40px;
    }
    ul li {
      list-style: none;
    }
<form name="geraTabela" action="RecebeForm.php" method="POST">
  <ul>
    <li>
      <input type="hidden" name="id_texto[]" value="1">
      <label> <span>Pai</span>
        <input type="text" name="Pai[]">
      </label>
      <label> <span>Filho</span>
        <input type="text" name="filho1[]">
      </label>
      <label> <span>Neto</span>
        <input type="text" name="neto[]">
      </label>
    </li>
    <br>
    <li>
      <input type="hidden" name="id_texto[]" value="2">
      <label> <span>Pai</span>
        <input type="text" name="pai[]">
      </label>
      <label> <span>Filho</span>
        <input type="text" name="filho2[]">
      </label>
      <label> <span>Neto</span>
        <input type="text" name="neto[]">
      </label>
    </li>
    <br>
    <li>
      <input type="hidden" name="id_texto[]" value="3">
      <label> <span>Pai</span>
        <input type="text" name="pai[]">
      </label>
      <label> <span>Filho</span>
        <input type="text" name="filho3[]">
      </label>
      <label> <span>Neto</span>
        <input type="text" name="neto[]">
      </label>
    </li>
  </ul>
  <!---->
  <button type="submit" name="btn">Enviar</button>
</form>

I would like the code to be printed as follows:

Pai 1
 Filho 1 de Pai 1
 neto 1 de Filho 1
 Filho 2 de Pai 1
 Neto 1 de Filho 2
 Neto 2 de Filho 2

Pai 2
 Filho 1 de Pai 2
 Filho 2 de Pai 2
 Neto 1 de Filho 2

I managed to 'tie' the Father with the Children through the ID. I'm having a hard time 'tying up' the grandchildren with the children I would just shed a light on how to accomplish this task. Thank you!

<?Php
if(isset($_POST['id_texto'])){
$id_texto = $_POST['id_texto'];
    foreach($id_texto as $id){
        if(isset($_POST['pai'])){
        $pai = $_POST['pai'];
            foreach($pai as $pais){
                if(isset($_POST["filho'.$id.'"])){
                $paragrafo = $_POST["filho'.$id.'"];
                    foreach($filho as $filhos){
                        if(isset($_POST["neto"])){
                        $neto = $_POST["neto"];
                            foreach($neto as $netos){

                            }
                        }
                    }
                }
            }
        }
    }
}
?>
    
asked by anonymous 07.08.2015 / 22:53

0 answers