Tengo una pregunta. Aquí está mi código
<p><strong style="color: blue;">IF</strong></p> <?php foreach ($data as $i => $key) : ?> <p><?php echo $key['symptoms'] ?></p> <p><strong style="color: green;">AND</strong></p> <?php endforeach ?> <p style="color: red;"> <strong>THEN</strong></p> <p><?php echo $key['disease_name'] ?></p>Pero, la salida es así.
IF symptoms A AND symptoms B AND symptoms C AND THEN disease AQuiero que desaparezca el último AND. ¿Alguien puede ayudarme por favor? :( Lo siento porque soy un novato aquí. ¡Gracias!
Debe comprobar si $i es menor que el último elemento de la matriz: $i < count($data) - 1 . Aquí hay un ejemplo:
<p><strong style="color: blue;">IF</strong></p> <?php foreach ($data as $i => $key) : ?> <p><?php echo $key['symptoms'] ?></p> <!-- only print AND if it is not the last element --> <?php if ($i < count ($data) - 1) { ?> <p><strong style="color: green;">AND</strong></p> <?php } ?> <?php endforeach ?> <p style="color: red;"> <strong>THEN</strong></p> <p><?php echo $key['disease_name'] ?></p>