//联系过我的经纪人 $appletChats=$this->AppletChat->orderBy('created_at','desc')->where([['user_id',$param['user_id']],['source',2]]) ->get(['send_user','created_at'])->toArray(); // 二维数组去重 $res = array(); foreach ($appletChats as $value){ if (!empty($value['send_user'])) { if (!isset($res[$value['send_user']])) { $res[$value['send_user']] = $value; } } } dd($res);