tp6多循环结果重组
作者:互联网
$group=Db::name('auth_group')->select();
foreach ($group as $v){
$v['auth_group_access']=Db::name('auth_group_access')->where('group_id',$v['id'])->select();
foreach($v['auth_group_access'] as $k1=>$v1){
$v1['user']=Db::name('user')->field('truename')->where('uid',$v1['uid'])->find();
$v['auth_group_access'][$k1]=$v1;
}
$data['group'][]=$v;
}
结果形式:
"group" => array:11 [▼ 0 => array:5 [▼ "id" => 1 "title" => "aaa" "auth_group_access" => think\Collection {#78 ▼ 0 => array:4 [▼ "id" => 1 "group_id" => 1 "uid" => 1 "user" => array:1 [▼ "truename" => "aaa" ] ] ] }
$group=Db::name('auth_group')->select(); foreach ($group as $v){ $auth_group_access=Db::name('auth_group_access')->where('group_id',$v['id'])->select(); $a=''; $b=''; foreach($auth_group_access as $k1=>$v1){ $user=Db::name('user')->field('truename')->where('uid',$v1['uid'])->find(); $a=$a.$v1['uid'].','; $b=$b.$user['truename'].','; } $v['auth_group_access']['uid']=$a; $v['auth_group_access']['truename']=$b; $data['group'][]=$v; }
结果:
"group" => array:11 [▼ 0 => array:5 [▶] 1 => array:5 [▼ "id" => 4 "title" => "ttt" "auth_group_access" => array:2 [▼ "uid" => "73,101" "truename" => "aaa,bbb" ] ]
标签:重组,group,uid,auth,access,tp6,循环,array,id 来源: https://www.cnblogs.com/fuxp/p/15114081.html