function getCat()
{
//sql语句 自行替换
$dt=getData("select c.category_id,cd.name,c.parent_id,c.sort_order,c.image from hb_category as c left join hb_category_description as cd on c.category_id=cd.category_id where c.status=1 and c.type=0 order by c.category_id desc");$arr=array();
//将分类id 赋予key 以便更好的排序
foreach ($dt as $key => $value) {
$arr[$value['category_id']]=$value;
}
//根据父id 进行分类
foreach ($arr as $key => $value) {
$arr[$value['parent_id']]['son'][]=$arr[$key];
}
$menu=array();
foreach ($arr as $key => $value) {
if(@$value['parent_id'] == 0 && isset($value['parent_id']))
$menu[]=$value;
}
print_r($menu);
}