<?php
#Ex: Short Set Ranking Hosting Provider Founded By Year
// INPUT
$Hosting_Years = array(
'Bluehost' => 2003,
'Dreamhost' => 1996,
'Hostinger' => 2004,
'HostGator' => 2002,
'A2 Hosting' => 2001,
'GreenGeeks' => 2008,
'WP Engine' => 2010,
'Inmotion' => 2001,
'SiteGround' => 2004,
'Nexcess' => 2000,
);
function setRanking($standings) {
$rankings = array();
arsort($standings);
$rank = 1;
$tie_rank = 0;
$prev_score = -1;
foreach ($standings as $name => $score) {
if ($score != $prev_score) { //this score is not a tie
$count = 0;
$prev_score = $score;
$rankings[$name] = array('score' => $score, 'rank' => $rank);
} else { //this score is a tie
$prev_score = $score;
if ($count++ == 0) {
$tie_rank = $rank - 1;
}
$rankings[$name] = array('score' => $score, 'rank' => $tie_rank);
}
$rank++;
}
return $rankings;
}
// OUTPUT
$set_Host_Ranking = setRanking($Hosting_Years);
foreach($set_Host_Ranking as $host => $value){
echo "<br> Rank: ".sprintf("%03d", $value['rank']). "   Founded in : ".$value['score']. "  Host: ".$host;
}
?>
According To Question:
#Ranking/Position on value of array in PHP
#Rank Of An Element In An Array
#What Is Rank Of An Array
#Array Ascending Order In PHP
#PHP Sort Multidimensional Array By Value Alphabetically
#Ksort Multidimensional Array PHP
#PHP Sort Multidimensional Array By Key