如何循环浏览帖子并查找是否有任何答案为“否”?
到目前为止,这是我的代码:
if($_POST["minRequirementsForm"]) {
foreach($_POST as $key => $value) {
$_SESSION['minrequirements'][$key] = $value;
}
}
提前致谢。
答案 0 :(得分:3)
您可以使用in_array()或array_search()并保存循环:
if (in_array('no', $_POST)) echo 'they said no'.
if (($key = array_search('no', $_POST)) !== false) echo "$key was answered with no";
答案 1 :(得分:2)
if($_POST["minRequirementsForm"]) {
foreach($_POST as $key => $value) {
if ('no' == $value) {
// do something
}
$_SESSION['minrequirements'][$key] = $value;
}
}
答案 2 :(得分:0)
$NoAsnwers = false;
if($_POST["minRequirementsForm"]) {
foreach($_POST as $key => $value) {
if ($value == 'No') $NoAsnwers = true;
}
}
也许是这样?