0

以下に示す2つのforループがあります

foreach($result_access as $acc){
   $usr_access_id[] = $acc->id;
   $usraccess[] = $acc->rules;
}

>更新

     foreach($somearray as $someid){//Updated
        foreach($usraccess as $accessusr){
          if(in_array($someid,$usraccess)){
            $myid = ??;///Here i want the $usraccess associated $acc->id, how can I get that? 
          }
        }
      }

ご覧のとおり、現在の配列に関連付ける必要がある$myid割り当てを取得する必要があります$acc->id$usraccess

4

2 に答える 2

2

これが正しい解決策です:

foreach ($result_access as $acc) {
    if (in_array($someid, $acc->rules)) {
        $myid = $acc->id;
    }
}

非常識な解決策は次のようになります。

...

foreach($usraccess as $i => $accessusr){
  if(in_array($someid,$usraccess)){
    $myid = $usr_access_id[$i];
  }
}
于 2012-07-05T12:33:24.043 に答える
0

これは、あなたの望むことですか?

foreach($result_access as $acc){
   $usr_access_id[] = $acc->id;
   $usraccess[ $acc->id ] = $acc->rules;
}

foreach($usraccess as $accessusr){
  if(in_array($someid,$usraccess)){
    $myid = $usraccess[ $someid ] ;///Here i want the $usraccess associated $acc->id, how can I get that? 
  }
}
于 2012-07-05T12:33:04.803 に答える