2013-02-15 28 views
0

我應該使用什麼驗證碼,當通過與多維數組匹配形式的數據

$ _GET [「羣」],

$ _GET [「章」接收到的所有數據,返回FALSE ]

$ _GET [ '文章']

不與$規律[$ MATCH組] [$ chapter] [$ article]多維數組已經設置?

我問,因爲我打算一次回顯一篇文章中的$法則多維數組,如果這樣的數組構造不存在,則返回錯誤。

非常感謝!

<?php 

session_start(); 
$laws = array(
    "group1" => array(
     "1" => array(
      "1" => "This is article (1) in chapter (1) of (group1)", 
      "2" => "This is article (2) in chapter (1) of (group1)", 
      "3" => "This is article (3) in chapter (1) of (group1)", 
     ), 
     "2" => array(
      "1" => "This is article (1) in chapter (2) of (group1)", 
      "2" => "This is article (2) in chapter (2) of (group1)", 
      "3" => "This is article (3) in chapter (2) of (group1)", 
     ), 
    ), 
    "group2" => array(
     "1" => array(
      "1" => "This is article (1) in chapter (1) of (group2)", 
      "2" => "This is article (2) in chapter (1) of (group2)", 
      "3" => "This is article (3) in chapter (1) of (group2)", 
     ), 
     "2" => array(
      "1" => "This is article (1) in chapter (2) of (group2)", 
      "2" => "This is article (2) in chapter (2) of (group2)", 
      "3" => "This is article (3) in chapter (2) of (group2)", 
     ), 
    ) 
); 


$_SESSION['group'] = $_GET['group']; 
$_SESSION['chapter'] = $_GET['chapter']; 
$_SESSION['article'] = $_GET['article']; 

$group = $_SESSION['group']; 
$chapter = $_SESSION['chapter']; 
$article = $_SESSION['article']; 



// Echo Article from $laws multidimensional Array 

echo $laws[$group][$chapter][$article]; 
?> 
+2

感謝您發佈您的標題。我正在墜入窒息,但現在我醒了。 – 2013-02-15 18:57:41

回答

0

如果你想返回FALSE時,所有接收到的數據不匹配:

$grp= $_GET['group']; 
$chap = $_GET['chapter']; 
$art = $_GET['article']; 
return isset($laws[$grp]) || isset($laws[$grp][$chap]) || isset($laws[$grp][$chap][$art]); 

但我認爲你想返回FALSE當任何接收到的數據的不匹配,則應使用方法:

return isset($laws[$grp][$chap][$art]); 
+0

哇!有用。非常感謝你的宏偉答案。 – user2075752 2013-02-15 19:41:47