public function commentSort($data ,$pid = 0, $ischild=false,$fatherindex=0)
{
   static $arr = array() ;
   foreach ($data as $key => $value) {
       if($value['pid'] == $pid){
           if($ischild){
               //下面相当于
               //array_push($arr[$fatherindex]['children'],$value) ;
               static $child = array() ;
               $child[$fatherindex][] = $value ;
               $arr[$fatherindex]['children'] = $child[$fatherindex] ;
               $fatherindex = $fatherindex;
           } else {
               $arr[$key] = $value ;
               $arr[$key]['children'] = [] ;
               $fatherindex = $key ;
           }
           //继续当前id的子类
           self::commentSort($data,$value['id'],true,$fatherindex) ;
       }
   }
   return (array)$arr;
}

 

相关文章:

  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-12-13
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案