0

我有两个下面给出的循环

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分配的 get$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 回答