$second = false; } else { $json .= ','; } $json .= '{ "id" : ' . $m->get_id() . ', "name" : "' . $m->get_name() . '", "description" : "' . $m->get_description() . '", "dosification" : "' . $m->get_dosification() . '", "periodicity" : "' . $m->get_periodicity() . '" }'; } $json .= '],'; $json .= ' "therapies" : ['; $therapies = $c->get_therapies(); $third = true; foreach ($therapies as $th) { if ($third) { $third = false; } else { $json .= ','; } $json .= '{ "id" : ' . $th->get_id() . ', "name" : "' . $th->get_name() . '", "description" : "' . $th->get_description() . '" }'; } $json .= '],