2012-01-04 63 views
0

我想用PHP检查我的输入表单。表单的多维数组

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

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

例如

$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 
       ) 
) 

有人能帮我吗?

+0

$ false = array(); $ false [] = $ _POST; 这样的事情? – DarkMantis 2012-01-04 13:00:51

+0

在我的例子中,我在数组中写入“false”输入“name”,现在我想把原因放到数组kay“name”中。 – fteinz 2012-01-04 13:11:17

+0

$ false = array(); $ false ['name'] [] = $ _POST ['name'];将工作 – DarkMantis 2012-01-04 14:40:08

回答

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!'; 
} 
+0

感谢它的工作......但现在我无法找到in_array的关键名称。我想测试:if(in_array(“name”,$ false)){// do something} – fteinz 2012-01-04 13:23:35

+0

if($ false ['name']){// do something} – Stefan 2012-01-04 14:44:07

+0

if(array_key_exists('name',$假)){//做点什么} – DarkMantis 2012-01-04 14:59:41