我想要的效果:
不使用array_reduce 的效果 :
代码:
public function teamList($userId,$good_id){$nowbuyers = $this->order->where('good_id',$good_id)->count();$data = GroupTotalOrder::alias('t_order')->where('merchant_Id',$userId)->leftJoin('dg_goods good','t_order.good_id = good.id')->field("t_order.*,good.id,good.photo,good.name,good.type,good.price,good.tag")->select()->toArray();if(!$data){return $this->fail("没有找到团购的香相关信息");}$data = array_reduce($data, function ($carry, $item) use ($nowbuyers) {$carry[] = array_merge($item, ['nowbuyers' => $nowbuyers]);return $carry;}, []);// dump($data);die();$data['nowbuyers'] = $nowbuyers;return $this->success("获取数据成功",$data);}