2

次のようなコードのスニペットがあります。

if(array_key_exists('uid',$_SESSION)){
     $userdata->readUser($_SESSION['uid']); 
     $ACL = new ACL($_SESSION['uid']);
     $userPerms = $ACL->setACL();
     if(!in_array_r("adminUI",$userPerms['perms'],true)){
        echo "Couldnt fine adminUI in:";
         var_dump($userPerms['perms']); 
     }
}

in_array_r 関数は次のとおりです。

function in_array_r($needle, $haystack, $strict = false) {
    foreach ($haystack as $item) {
        if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
            return true;
        }
    }

    return false;
}

私が得たもの: in_array() と多次元配列

ただし、これの出力は次のとおりです。

Couldnt fine adminUI in:
array(2) {
  [0]=>
  array(1) {
    ["perm_desc"]=>
    string(7) "adminUI"
  }
  [1]=>
  array(1) {
    ["perm_desc"]=>
    string(9) "apiAccess"
  }
}

STRICTなしで配列をチェックするように関数を変更すると、針が見つかりますが、厳密なチェックでは失敗します...

私はこれを理解しようとして机に頭をぶつけています。

編集

Jan Schejbal は、このコードが完全に正常に動作することを指摘するほど素晴らしいものでした。作業ディレクトリを理解するのに十分な一貫性がありませんでした。Jan Schejbal さん、ありがとうございました。

4

1 に答える 1

1

I originally posted this as a comment, but since it indeed was the answer to the question...

If you have a totally WTF error:

  1. Change the error message and run the program again. If it shows the original error message, you are running a different file than you are editing (e.g. not uploading, wrong directory) or have another copy of the error-message generating code somewhere.

  2. Check your files for unprintable characters using an editor that shows them

No. 1 is one of the most common reasons for unexplainable errors.

于 2013-01-28T03:53:26.210 に答える