循环通过发布的值来查看是否有相等的“否”

时间:2010-11-02 13:35:10

标签: php

如何循环浏览帖子并查找是否有任何答案为“否”?

到目前为止,这是我的代码:

if($_POST["minRequirementsForm"]) {
    foreach($_POST as $key => $value) { 
        $_SESSION['minrequirements'][$key] = $value;
    }
}

提前致谢。

3 个答案:

答案 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;
    }
}

也许是这样?