我的代码不工作,它不检查,我该怎么办?
$ex_requests = explode(',',"1,2");
if(in_array($ex_requests, array('1', '2'))) {
echo "OK";
} else {
exit;
}
返回空白页
当您将array
作为needle
(第一个参数,要搜索的项)传递给in_array()
时,haystack
(第二个参数,要搜索的项)必须是array of arrays
。因此,在您的情况下,以下操作将起作用:
$ex_requests = explode(',',"1,2");
// in the next line, the first argument is an array
// and the second argument is an array of arrays...
if(in_array($ex_requests, array(array('1','2'))))
{
echo "OK";
}
else
{
echo "NOT OK";
}
这将按预期打印OK