Hello, I have this function that gets me an array but when I try, for example, to obtain the name in the following way course[0]['name'] it tells me that the object of type Course cannot be used as an array.
public function mostrarCurso(){
$db = BaseDatos::conectar();
$listadoCurso = [];
$select = $db->query('SELECT * FROM Curso');
/*Si no están los setters no se mostrarán en la tabla*/
foreach ($select->fetchAll() as $curso) {
// foreach ($select->fetch(PDO::FETCH_ASSOC) as $curso) {
$myCurso = new Curso();
$myCurso->setIdCurso($curso['id_curso']);
$myCurso->setNombreCurso($curso['nombre']);
$myCurso->setCantAlumnos($curso['cant_alumnos']);
$myCurso->setFechaInicio($curso['fecha_inicio']);
$myCurso->setFechaFin($curso['fecha_fin']);
$myCurso->setNivelCurso($curso['nivel_curso']);
$myCurso->setFoto($curso['foto']);
$myCurso->setEstadoCurso($curso['estado']);
$listadoCurso[] = $myCurso;
}
return $listadoCurso;
}
The problem was that what I was passing were objects, what I do is json_decode(json_decode()) to generate an Array.
And in this way I can recover the data as follows,