如何匹配数组中的特定值

时间:2016-09-20 08:58:48

标签: php

我试图匹配数组值。我如何匹配以下代码?

$os = array("CATEGORY=OS", "SYSTEM_NAME like '%A001%'", "CATEGORY=DB");
if (in_array("CATEGORY", $os)) {
    echo "Got it";
}

我需要匹配数组中的CATEGORY我该怎么做?

修改2

where (CATEGORY = 'OS' AND SYSTEM_NAME like '%A001%' AND CATEGORY = 'DB' AND SYSTEM_NAME like '%A001%')

我有类似这样的问题,我需要在类别occrence之前将AND替换为OR

预期输出

where (CATEGORY = 'OS' AND SYSTEM_NAME like '%A001%' OR CATEGORY = 'DB' AND SYSTEM_NAME like '%A001%')

1 个答案:

答案 0 :(得分:1)

使用这个preg_grep()php函数

$os = array("CATEGORY=OS", "SYSTEM_NAME like '%A001%'", "CATEGORY=DB");
if (preg_grep("/CATEGORY/", $os)) {
   echo "Got it";
}    

有关详情,请参阅this