我在这里有这个代码:
if (in_array("Notecards", $array) || in_array("Poster", $array)){
echo "Match found";
}else{
echo "Match not found";
}
Run Code Online (Sandbox Code Playgroud)
我的问题是海报可以是海报1,海报2,海报3,海报4等.
如果在那里说如果海报然后空间然后一个数字不在我的阵列?
使用preg_grep如下:
if (in_array("Notecards", $array) || preg_grep("/Poster\s\d+/", $array)){
echo "Match found";
}else{
echo "Match not found";
}
Run Code Online (Sandbox Code Playgroud)
我冒昧地假设你可能有超过0-9的海报,在这种情况下\d+匹配一个或多个数字(海报10,海报800等).如果您只需要一个数字,请删除+.