表单的多维数组

时间:2012-01-04 12:56:38

标签: php multidimensional-array validation

我想用PHP检查我的输入表单。

我想用假输入框名称和原因填充数组。

但我不知道我是如何得到多维的。

e.g。

$false = array();

if (!isset($_POST['name']) OR $_POST['name'] == "") {
    array_push($false, "name");
    //and here I want to to get a multi-dimension array and put the reason of the fales the the arraykey name
    //e.g. Sorry the name is missing!
}

if (strlen($_POST['name']) < 3) {
    array_push($false, "name");
    //and here I want to to get a multi-dimension array and put the reason of the fales the the arraykey name
    //e.g. Sorry the name is to short!
}

现在我想得到(如果输入表格名称在提交后没有任何内容),例如

false
(
    [0] => name
                (
                    [0] => Sorry the name is missing!
                    [1] => Sorry the name is to short!
                    [2] => etc etc
                )
    [1] => etc
                (
                    [0] => etc etc
                )
)

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

$false = array();

if (!isset($_POST['name']) OR $_POST['name'] == "") {
    $false['name'][] = 'Sorry the name is missing!';
}

if (strlen($_POST['name']) < 3) {
    $false['name'][] = 'Sorry the name is to short!';
}