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)