`

public static function getTree($list, $pk = 'id', $pid = 'pid', $child = 'child', $root = 0)
{
    $tree = array();
    foreach ($list as $key => $val) {
        if ($val[$pid] == $root) {
            //获取当前$pid所有子类
            unset($list[$key]);
            if (!empty($list)) {
                $child = Translator::getTree($list, $pk, $pid, $child, $val[$pk]);
                if (!empty($child)) {
                    $val['child'] = $child;
                }else{
                    $val['child'] = [];
                }
            }
            $tree[] = $val;
        }
    }
    return $tree;
}

`