qxandxt

导航

无限级分类接口

传递一个pid字段递归即可

/**
 * 无限级分类
 * @param $data
 * @param int $pid
 * @return array
 */
function getTree($data, $pid=0){
    $arr  = array();
    foreach ($data as $key=>$value){
        if ($value['pid'] == $pid){
            $value['children'] = getTree($data,$value['id']);
            $arr[] = $value;
        }
    }
    return $arr;
}

 

posted on 2021-11-30 18:03  qxandxt  阅读(20)  评论(0编辑  收藏  举报