有条件地比较string中的所有值

时间:2014-04-01 16:32:50

标签: php arrays variables if-statement conditional

我正在尝试编写一个条件,检查$variable是否等于以下字符串中的任何值

$category_id = "348,349,398,399,400,402,404,406,410,415,417,419,421,423,425,434,436,438,439,442,350,444,446,448,450,458,460,461,464,468,470,475,479,480,481,483,485,487,489,491,492,498,499,501,503,506,352,509,511,513,521,523,533,535,538"

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

if(in_array($searchValue,explode(",",$category_id)))
{
   // in there
}

<强> Fiddle