我有这个代码,我希望有一个包含必填字段的数组,并且只循环遍历列表中的字段。
//Required Fields
$validationFields = array(
"username" => "",
"email" => "",
"password" => ""
);
foreach ($_POST as $key => $value)
{
$asd = in_array($_POST[$key], $validationFields);
echo "<pre>";
var_dump($asd);
echo "</pre>";
if(in_array($_POST[$key], $validationFields))
{
if($_POST[$key] == "")
{
$error = "has-error";
}
}
}
答案 0 :(得分:0)
尝试查看array_intersect
或您需要array_intersect_keys