简单无限级分类实现

所有分类数据  $arr  

/**

*$arr  所有分类数据

*$pid  父级id  第一次为0

*/

public function getson($arr,$pid){
$test=[];
foreach ($arr as $key => $v) {
if ($v['parent_id']==$pid) {
$v['son']=$this->getson($arr,$v['id']);
$test[]=$v;
}
               }
return $test;

}


猜你喜欢

转载自blog.csdn.net/qq_41949579/article/details/80374120