如何匹配数组中的特定值
问题描述:
Im trying to match the array value. how can i match the below code ?
$os = array("CATEGORY=OS", "SYSTEM_NAME like '%A001%'", "CATEGORY=DB");
if (in_array("CATEGORY", $os)) {
echo "Got it";
}
I need to match the CATEGORY
in array how can i do that ?
Edit 2
where (CATEGORY = 'OS' AND SYSTEM_NAME like '%A001%' AND CATEGORY = 'DB' AND SYSTEM_NAME like '%A001%')
I have query something like this i need to replace the AND
as OR
before category occrence
Expected Output
where (CATEGORY = 'OS' AND SYSTEM_NAME like '%A001%' OR CATEGORY = 'DB' AND SYSTEM_NAME like '%A001%')
我试图匹配数组值。 我如何匹配以下代码? p>
$ os = array(“CATEGORY = OS”,“SYSTEM_NAME like'%A001%'”,“CATEGORY = DB”);
if(in_array(“CATEGORY”,$ os)){
echo“得到它”;
}
code> pre>
我需要匹配 数组中的CATEGORY code>我该怎么做? p>
编辑2 strong> p>
where(CATEGORY ='OS'和SYSTEM_NAME喜欢'%A001%'和CATEGORY ='DB'和SYSTEM_NAME喜欢'%A001%')
code> pre>
我有这样的查询 我需要在类别occrence之前将 AND code>替换为 OR code> p>
预期输出 strong> p> \ n
其中(CATEGORY ='OS'和SYSTEM_NAME喜欢'%A001%'或CATEGORY ='DB'和SYSTEM_NAME喜欢'%A001%')
code> pre> \ n div>
答
use this preg_grep() php function
$os = array("CATEGORY=OS", "SYSTEM_NAME like '%A001%'", "CATEGORY=DB");
if (preg_grep("/CATEGORY/", $os)) {
echo "Got it";
}
For more reference see this