二个foeache 实现数据的递归

 

 

 $type =Db::name('shop_goods_spu_specification')//查询商品规格维度
->field('id,parent_id,title')
->where('spu_id',$goods_id)
->select();
$type1=Db::name('shop_goods_spu_specification_sub')//查询商品规格维度详情
->field('id,spec_id,title')
->where('id','in',$arr)
->select();
//dump($arr);die();
$arr=[];//处理数据进行组合数组进行返回
foreach ($type1 as &$v){
$arr[$v['spec_id']][]=$v;
}
foreach ($type as &$value){
$value['son']=$arr[$value['id']];
}
// dump($type);die();
return $type; //返回数据
posted @ 2021-05-15 15:40  胡良庆  阅读(49)  评论(1编辑  收藏  举报