DEV Community 👩‍💻👨‍💻

Arif Setya Nugraha
Arif Setya Nugraha

Posted on

how show echo only once in foreach and if else if condition

here is my json data

{ "order_id":"#BCB28FB2" "salutation":"Mr", "name":"Testing Data", "cart":[ { "id":13, "name":"tes1", "treatment_type":"tes", }, { "id":14, "name":"tes2", "treatment_type":"tes", }, { "id":15, "name":"Panel", "treatment_type":"panel", }, { "id":16, "name":"Paket", "treatment_type":"paket", }, ] }

and this my code

foreach($data['cart'] as $value){
   if($value['treatment_type'] == 'tes'){
      echo "Its a tes<br>";
   elseif($value['treatment_type'] ==

Top comments (0)


Thank you.

Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.