title: PHP Reward points to leaderboard and account for ties
body: <p>Okay I've been beating my head over this one for a while and google searching trying to find anything to lead me in the right direction to no avail.</p>
  
  <p>So I have a ranked leaderboard array like so:</p>
  
  <pre><code>[1] = array('points' =&gt; '99', 'rank' =&gt; '1');
  [2] = array('points' =&gt; '90', 'rank' =&gt; '2');
  [3] = array('points' =&gt; '90', 'rank' =&gt; '2');
  [4] = array('points' =&gt; '80', 'rank' =&gt; '4');
  [5] = array('points' =&gt; '70', 'rank' =&gt; '5');
  [6] = array('points' =&gt; '70', 'rank' =&gt; '5');
  </code></pre>
  
  <p>Then I have a reward point system with a predefined array to award points based on rank:</p>
  
  <pre><code>[1]=10;
  [2]=9;
  [3]=8;
  [4]=7;
  [5]=6;
  [6]=5;
  </code></pre>
  
  <p>If it weren't for ties I'd just match the two arrays up and award points as so based off of the array keys.  But, since I'm allowing for ties I'm trying to split the tied reward points between all tied users. So with the references above players 2 and 3 who are tied at 2nd would split the rewards point 9 and 8... so both would be awarded 8.5 points.</p>
  
  <p>So the end result I'm looking for when merging both arrays would be:</p>
  
  <pre><code>[1] = array('points' =&gt; '99', 'rank' =&gt; '1', 'reward' =&gt; '10');
  [2] = array('points' =&gt; '90', 'rank' =&gt; '2', 'reward' =&gt; '8.5');
  [3] = array('points' =&gt; '90', 'rank' =&gt; '2', 'reward' =&gt; '8.5');
  [4] = array('points' =&gt; '80', 'rank' =&gt; '4', 'reward' =&gt; '7');
  [5] = array('points' =&gt; '70', 'rank' =&gt; '5', 'reward' =&gt; '5.5');
  [6] = array('points' =&gt; '70', 'rank' =&gt; '5', 'reward' =&gt; '5.5');
  </code></pre>
  
  <p>The leaderboard can constantly change until the end of the day so I'm trying not to make it too complicated.  I'm just wondering if anyone can point me to something they've seen that would help me out or if they had any implementation ideas.  </p>
  
  <p>I the part I'm struggling with the most in my attempt is looping through the leaderboard array and continuously looking forward for the 'rank' to be the same to then know what I need to sum up and split out, while also knowing I can skip the array ahead instead of performing this same test on the next item that I just went through in my lookahead.  Sorry If I'm confusing, but I'm obviously confused.</p>