Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

394
Views
¿Cómo puedo eliminar 'Y' en el último bucle (para cada uno)?

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 A

Quiero que desaparezca el último AND. ¿Alguien puede ayudarme por favor? :( Lo siento porque soy un novato aquí. ¡Gracias!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!