0

Is there a way to reduce the code if I have many "ands" and "ands" in my if request for the same value? I would like to need $row['animal'] only one time:

  if ($row['animal'] == "cat") or 
     ($row['animal'] == "dog") or 
     ($row['animal'] == "bird") or 
     ($row['animal'] == "monkey") or 
     ($row['animal'] == "mouse") or 
     ($row['animal'] == "hedgehog"){
     echo "many animals";}
peace_love
  • 6,229
  • 11
  • 69
  • 157

1 Answers1

0
echo in_array($row['animal'], array('cat', 'dog', 'bird', 'monkey', 'mouse','hedgehog'))
      ? 'many animals' 
      : 'no animals';
peace_love
  • 6,229
  • 11
  • 69
  • 157