how to achieve second-level comments like a brief book?
my existing fields are as follows:
id pid id article_id id
my original implementation is as follows
/**
* @param $data array
* @param $pid string parent_id
* @param $id string comm_id
* @param $p_id int id
* @return array
*/
public function getSubTree($data , $pid , $id , $p_id = 0) {
$tmp = array();
foreach ($data as $key => $value) {
$value["avatar"] = getAvatar($value["from_user_id"]);
if($value[$pid] == $p_id) {
$value["child"] = $this->getSubTree($data , $pid , $id , $value[$id]);
$tmp[] = $value;
}
}
return $tmp;
}
the comment structure obtained is as follows