1
I have two Inputs (curso[]
and formacao[]
) html
and when loop with the 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;
}
I’m not sure but I believe that you should not have the forechs chained, should be separated, can confirm this?
– rray
What is the relationship like? It is a course for a training?
– Allan Andrade
I don’t know where this information comes from, the most reliable would be to have the course
id
of training in the database, so you know exactly which courses are in which formations, only with the question code it seems that they are separated.– rray
I did not understand the relationship of the Formation with the Courses since the two are independent arrays. If it is a formation, with several courses, coming these two separate arrays, as you visualize correctly link the courses to the corresponding formations?
– Antonio Alexandre
Shouldn’t it be private $Training[]; private $Courses[];? Otherwise it doesn’t make sense the setFormation since the builder already does this!
– Carlos Rocha
This data is not generated in a database.
– William
@William does not need to add SOLVED in the title, the site works different from forums, and we recommend you post as a response below the way you solved the problem, and mark as accepted by clicking on
v
– user28595