0

私の if ステートメントは、変数の 1 つを調べ続け、or ステートメントを調べて true を返します。見せる前にコーディングを説明するのは嫌いです...

if($relLoc[1] <= "32" AND $map['locationpadding'] == "0px 0px -32px 0px" OR $map['locationpadding'] == "0px 0px -32px -32px" OR $map['locationpadding'] == "0px -32px -32px 0px")
{
    die();
}

したがって、私がい$map['locationpadding'] == "0px 0px -32px -32px"$relLoc[1] == "380"die();まだ実行されている場合。

しかし、私がいる場合、その場所0px 0px -32px 0pxにいるまで実行されません。32

4

2 に答える 2

2

論理ステートメントを正しくグループ化していません。私はPHPを知らないので、構文がオフになっている可能性がありますが、基本的にはこれが必要です:

if($relLoc[1] <= "32"  AND **(** $map['locationpadding'] == "0px 0px -32px 0px" OR $map['locationpadding'] == "0px 0px -32px -32px" OR $map['locationpadding'] == "0px -32px -32px 0px"**)** ){
            die();
        }

ブール ステートメントの正しいグループを示す追加の括弧に注目してください。元の投稿で行ったことは次のとおりです。

if relLoc == 32 AND  $map['locationpadding'] == "0px 0px -32px 0px

  +  
OR $map['locationpadding'] == "0px 0px -32px -32px"   
  + 
OR $map['locationpadding'] == "0px -32px -32px 0px

したがって、提供したサンプルでは、​​次のようになります。

$map['locationpadding'] == "0px 0px -32px -32px" and the $relLoc[1] == "380" 

つまり:

   False + True + False = True
于 2012-12-14T19:09:33.007 に答える
0

あなたが望むように見えます:

if($relLoc[1] <= "32" AND ($map['locationpadding'] == "0px 0px -32px 0px" OR $map['locationpadding'] == "0px 0px -32px -32px" OR $map['locationpadding'] == "0px -32px -32px 0px")){
//                        ^ added                                                                                                                                                ^ added

括弧を使用してサブ条件を区切ります。そうしないと、最初の条件の関連性が低くなります。これは、その後に OR x OR x OR x があるため、条件全体が true に評価されるためには、OR の 1 つだけが true に評価される必要があるためです。

于 2012-12-14T19:09:41.797 に答える