<?php
   /**
     * 生成无限级分类
     * @param $list 数据
     * @param string $pk 主键ID
     * @param string $pid 子ID
     * @param string $son 子级字段
     * @param int $root
     * @return array
     */
    protected function tree($list,&nbsp;$pk = 'id', $pid&nbsp;=&nbsp;&#39;pid&#39;,&nbsp;$son = 'son', $root = 0)
    {
        $tree     = array();
        $packData = array();
        foreach ($list&nbsp;as&nbsp;$data) {
            $packData[$data[$pk]]&nbsp;=&nbsp;$data;
        }
        foreach ($packData&nbsp;as&nbsp;$key => $val) {
            if ($val[$pid] == $root) {
                $tree[]&nbsp;=&nbsp;&amp;$packData[$key];
            } else {
                $packData[$val[$pid]][$son][] = &$packData[$key];
            }
        }
        return $tree;
    }
?>