$get_categories_tree = get_categories_tree();
$smarty->assign('category_1', RandArray($get_categories_tree['634'],7));
$smarty->assign('category_2', RandArray($get_categories_tree['683'],6));
$smarty->assign('category_3', RandArray($get_categories_tree['754'],4));
$smarty->assign('category_4', RandArray($get_categories_tree['837'],3));
function RandArray($arr,$num=4){ $rand_arr = array_rand($arr['cat_id'],$num); // 随机4个类别 foreach($rand_arr as $k=>$v){ $f[$k] = $arr['cat_id'][$v]; } return $f; }