2012-01-04 134 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