我在下面给出了两个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
应与当前{{1}}数组相关联
答案 0 :(得分: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];
}
}
答案 1 :(得分: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?
}
}