Duplicate items in Foreach

1

I have two Inputs ( curso[] and formacao[] ) html and when looping with foreach and starts to duplicate the items that are within the second foreach

This is my class

class Pessoa {

private $Formacao;
private $Cursos;

function __construct($Formacao,$Cursos)
{

    $this->Formacao =  (array) $Formacao;
    $this->Cursos = (array) $Cursos;
}

public function setFormacao($Formacao){
    $this->Formacao = $Formacao;
}

public function getFormacao(){

    return $this->Formacao;
}

public function setCursos($Cursos){
    $this->Cursos = $Cursos;
}

public function getCursos(){
    return $this->Cursos;
}

public function getBody(){

    foreach ($this->getFormacao() as $formacao) {
            $body = "<ul><li>{$formacao}";
            foreach ($this->getCursos as $cursos) {
                $body.= "{$cursos}</li></ul>";
            }   
    }

    return $body;
}
    
asked by anonymous 09.01.2017 / 15:40

1 answer

1

I ended up finding the solution. It was very simple I used the for instead of the foreach, which is better for controlling iterations.

    
10.01.2017 / 21:31