jeudi 20 mai 2021

Condition check inside foreach loop

I want to filter data where $data['stock'] != 0 from an json array. Can I put the condition check inside the foreach loop? Or, is there any better way to execute the same?

foreach($json['items'] as $data)
{
  if(!$data['stock'] == 0) {
    echo 'Success';
  }
} 

Aucun commentaire:

Enregistrer un commentaire