/**
* 递归生成分类树
* @param array $item 分类数据
* @param int $parent_id 父id
* @param string $sub 子类名称
* @return array
*/
public static function getTree($item = array(), $parent_id = 0, $sub = 'children')
{
$data = array();
foreach ($item as $key => $val) {
if ($val['parent_id'] == $parent_id) {
$children = self::getTree($item, $val['id'], $sub);
if ($children) {
$val[$sub] = $children;
}
unset($val['parent_id']);
$data[] = $val;
}
}
return $data;
}