title: Ranking within a PHP array
body: <p>I have a seemingly simple ranking-type problem associated with php arrays, unfortunately after much research it has defeated me:</p>
  
  <p>I have a simple array where the keys are names of people and the values are just associated numbers:</p>
  
  <pre><code>$myArray = Array("David"=&gt;36, "James"=&gt;24, "Sarah"=&gt;70, "Mary"=&gt;55);
  </code></pre>
  
  <p>Here’s the challenge: <em>Given</em> a name, what is their <em>rank</em> within the array? For example: Sarah=rank1; It seems simple because I figured I could just sort the array by the values then loop though to the required name to get the rank. However, weirdly when I sort the array it just unhelpfully returns 1! </p>
  
  <pre><code>print_r(asort($myArray)) = 1 (??)
  </code></pre>
  
  <p>I suppose I could put the array in an MySQL table but that seems a bit heavy handed. Is anyone aware of a php solution? Where am I going wrong with the sort? I've read the documentation <a href="http://uk.php.net/manual/en/array.sorting.php" rel="nofollow" title="PHP Array sorting doc">here</a> and it seems asort is the appropriate function (preserves association and sorts on values).</p>
  
  <p>Thanks<br />
  The Grinch</p>