如果我有很多" ands"有没有办法减少代码?和" ands"在我的if请求相同的值?我只需要$row['animal']
一次:
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";}
答案 0 :(得分:0)
echo in_array($row['animal'], array('cat', 'dog', 'bird', 'monkey', 'mouse','hedgehog'))
? 'many animals'
: 'no animals';