0

すべてのデータが経由で受信されたときにFALSEを返すには、どの検証コードを使用する必要がありますか

$ _GET ['group']、

$_GET['章']

$ _GET ['article']

$ laws [$ group] [$ chapter] [$ article]多次元配列がすでに設定されていると一致しませんか?

$ laws多次元配列で一度に1つの記事をエコーバックするつもりなので、そのような配列構造が存在しない場合はエラーが返されます。

どうもありがとう!

    <?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];
?>
4

2 に答える 2

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]);
于 2013-02-15T19:07:49.570 に答える
0

特定の記事が特定のグループおよび章に存在するかどうかを確認したいだけの場合は、isset()http://php.net/manual/en/function.isset.phpを使用してください。

$article_exists = isset($laws[$group][$chapter][$article];
于 2013-02-15T19:09:05.647 に答える