function getUserRank($uid) { $api = new TS_API(); //获得等级规则 $rank_rule = $api->SystemUserRank_getAllRule(); //获得用户积分 $credit = $api->UserInfo_getCredit($uid); //如果积分为空则是初始等级 if (empty($credit)) { return $rank_rule[0]; } foreach ($rank_rule as $key => $rankValue) { foreach ($credit as $k2 => $score) { $min = $rankValue['rulemin'][$k2]; $max = $rankValue['rulemax'][$k2]; $comm[$k2] = !($min == 0 && $max == 0) ? $min <= $score && $score < $max : true; if (!$comm[$k2]) { unset($rank_rule[$key]); } } if (count(array_filter($comm)) != count($credit)) { continue; } else { return $rank_rule[$key]; } } //不满足任何条件。则为最高等级 return array_pop($rank_rule); }