Of course, almost half of the data in that array (and the code to extract it) is entirely redundant. If you've already verified that an integer is greater than fifty, you don't need to check again to see if it's at least fifty-one.
$rank = 97;
$rank_array = array(
'50'=>-1, // Rank0? Not high enough to rank
'101'=>'Rank1',
'171'=>'Rank2',
'281'=>'Rank3',
'451'=>'Rank4',
'631'=>'Rank5',
'816'=>'Rank6',
'1004'=>'Rank7',
'1201'=>'Rank8',
'1399'=>'Rank9',
'1601'=>'Rank10',
'1801'=>'Rank11');
$this_ranking = -1; // Rank0? No ranking yet
foreach($rank_array as $threshold=>$ranking)
{
if($rank<$threshold)
{
$this_ranking = $ranking;
break;
}
}
echo $this_ranking;
The above code also sets $this_ranking to a distinctive value in the cases (<50 or >1800) which aren't covered by the supplied ranking information.