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