I got an idea to write code based off of array_unique, but then I stumbled upon multi-sort
//using an array formatted like this:
$petlist[0]['name'] = 'pet1';
$petlist[0]['pts'] = 80;
$petlist[1]['name'] = 'pet2';
$petlist[1]['pts'] = 95;
$petlist[2]['name'] = 'pet3';
$petlist[2]['pts'] = 85;
$petlist[3]['name'] = 'pet4';
$petlist[3]['pts'] = 95;
$petlist[4]['name'] = 'pet5';
$petlist[4]['pts'] = 100;
//the below code sorts the array
foreach($petlist as $temp_list) {
$sort_pts[] = ($temp_list['pts']);
}
array_multisort($sort_pts, SORT_NUMERIC,SORT_DESC, $petlist);
//now we'll make the output for the list:
$out = '';
for($i=0; $i<sizeof($petlist); $i++) {
if(($i>0) && ($petlist[$i]['pts']==$petlist[$i-1]['pts'])) {
//the pet scored the same as the pet above and is in the same rank
$out.=($i).') ';
} else {
//this pet is in the next rank down
$out.=($i+1).') ';
}
$out.=$petlist[$i]['name'].' '.$petlist[$i]['pts']."<br />\n";
}
echo $out;
this will output something like this:
1) pet5 100
2) pet2 95
2) pet4 95
4) pet3 85
5) pet1 80
now all you need is some formatting and another variable to change the 4&5 to 3&4.