如果a == 1,2,3,7或10显示图像

时间:2017-08-23 09:15:30

标签: php

如果hop_nr是来自下面的数字,我怎么能显示这个图像。

if $man->hop_nr == AA44000000 or AA44738483 or AA45665839 or AA45697117 or AA45853322 or AA46593303 or AA46913044 or AA46913252 or AA46913631 or AA47362505 or AA47442114 or AA47452676 or AA47512000 or AA47542321 or AA47564838 or AA47592086, AA48622280 or AA48632711 or AA48644000 or AA48660000 or AA48666000 or AA49732000, AA49742000 or AA49781113 or AA49819308 or AA49831888 or AA49851138 or AA49890383 显示<img src="/media/store_logos/tlogo.png”>

2 个答案:

答案 0 :(得分:5)

您可以搜索一组数字:

$numbers = ['AA44000000', 'AA44738483', 'AA45665839', 'AA45697117', 'AA45853322', 'AA46593303', 'AA46913044', 'AA46913252', 'AA46913631', 'AA47362505', 'AA47442114', 'AA47452676', 'AA47512000', 'AA47542321', 'AA47564838', 'AA47592086', 'AA48622280', 'AA48632711', 'AA48644000', 'AA48660000', 'AA48666000', 'AA49732000', 'AA49742000', 'AA49781113', 'AA49819308', 'AA49831888', 'AA49851138', 'AA49890383']

if (in_array($man->hop_nr, $numbers)) {
    //show the image
}

in_array function的官方文档。

答案 1 :(得分:2)

$arr = array('AA44000000','AA44738483','AA45665839'); // all your values

使用in_array就像这样:

// search if value $man->hop exists in $arr
if (in_array($man->hop, $arr))
  {
        //do what you want
  }

阅读https://www.w3schools.com/php/func_array_in_array.asp