// 收到的主评论
$message = (new coachModel())->coachMessge($param); print_r($message);die;
// 组装主评论下的跟评论
$temp=array_column($message,'id');
$messagelists=CoachProblemModel::where('pid','in',$temp)
->field(['id','coach_id','create_time','member_id','is_reply','content','reply_id','pid'])
->select()->toArray();
print_r($messagelists);die;
依据 $message 里的 id 值,获取 $messagelists 数组里所有 pid 值跟 id 值雷同的重组在 $message[‘reply’] 字段下,冀望后果如下:
// 代码实现如下:
$pidMap = array_combine(array_column($message, 'id'), $message);
array_reduce($messagelists, function($carray, $item) use (&$pidMap) {if (isset($pidMap[$item['pid']])) {if (isset($pidMap[$item['pid']]['reply'])) {$pidMap[$item['pid']]['reply'] []= $item;} else {$pidMap[$item['pid']]['reply'] []= $item;}
} else {$pidMap[] = $item;
}
}, []);
print_r($pidMap);die;