Saturday 15 January 2011

arrays - PHP Reward points to leaderboard and account for ties -


OK I'm killing my head on this for a while and trying to find me to live I am here.

I have a ranking leaderboard array like:

  [1] = array ('numerals' =>, '99', 'rank' => '1'); [2] = array ('digits' => gt; '90', 'rank' => 2;); [3] = array ('digits' => 1, '90', 'rank' => 2;); [4] = array ('points' => gt; '80', 'rank' => 4;); [5] = array ('digits' => gt;' 70 ',' rank '=> 5'); [6] = array ('digits' => gt;' 70 ',' rank '=> 5');   

Then I have a reward point system with a predefined array for awards based on the rank:

  [1] = 10; [2] 9 =; [3] 8 =; [4] = 7; [5] 6 =; [6] = 5;   

If it were not for relations then I would only match two arrays and award points because this happens based on the array key. But, since I am allowing relations, I am trying to divide the reward points tied between all the tied users. So with the references given above 2 and 3, which are re-divided, they will be divided into 9 digits and 8 ... then both will be given 8.5 points.

So the end result I see is that both the arrays must be merged:

  [1] = array ('numerals' =>' 99 ',' rank '= & Gt;' 1 ',' Reward '= & gt; '10'); [2] = array ('numerals'> '90', 'rank' => 2; 'reward' => '8.5'); [3] = array ('numerals'> '90', 'rank' => 2; 'reward' => '8.5'); [4] = array ('points' => gtk; '80', 'rank' => 4; 'reward' => '7'); [5] = array ('number' => gtc: '70', 'rank' => 5 ',' reward '=> 5.5'); [6] = array ('numerals'> '70', 'rank' => 5 ',' reward '=> 5.5');   

Leaderboard can be changed continuously by the end of the day so I am not trying to make it very complicated. I am just thinking that someone can tell me about those things which they have seen who will help me or if they had any implementation idea

which part I struggled most of my efforts I am looping through the Leaderboard array and I am constantly waiting for the 'rank', after this I should know what I should do, while I also know that I Throat instead of the corresponding test items can skip ahead array do what I had just walked into his Letrahed. Sorry, if I am confused, but I am clearly confused.

This is probably what you want:

code array (array ('points' =>' 99 ',' rank '=> 1 array (' numerals' => '90', ' 'Number' = & gt; '2'), array ('number' => gt; '90', 'rank' => 2), array ('numerals' =' gt; '80' 'Array' = & gt; '4'), array ('number' => gt; '70 ',' rank '=> 5'), array ('digits' = & gt; 70' 'Rank' => 5 ')); $ rank = array (1 => 10, 2 => 9, 3 = & gt; 8 = 4 => 7, 5 = & gt; ; 6; 6 = & gt; 5); Foreign currency ($ person $ $ => as $ prop) $ $ reward = $ rank [$ prop ['rank']]; if (isset ($ persons) [$ Person + 1])) (if ($ $ Individuals [$ person + 1] ['rank'] == $ Sahara ['rank']) {$ reward = $ reward - 0.5;}} If (isset ($ persons [$ person-1]) {if ($ Individuals [$ person-1] ['rank'] == $ Sahara ['rank']) {$ reward = $ reward - 0.5;}} $ individuals [$ person] ['reward'] = $ reward =) echo '& Lt; Pre & gt;'; print_r ($ Individuals); Echo '& lt; Pre & gt; ';

Here's what you make a reward key and fill it with the person's rank based on the index in the $ ranks array. This example is not safe. I want to check you first, if the key is also present in the $ ranks array.

This example is very "raw" and is probably not flawed with various rankings, so you have to do yourself the last test.

Output

  array ([0] = & gt; array ([number] => 99 [rank] = & gt; ; 1 [reward] = & gt; 10) [1] => Array ([number] => 90 [rank] => 2 [reward] => 8.5) [2] = & Gate; Array ([number] => [rank] => 2 [inam] => 8.5) [3] => Array ([number] => 80 [rank] => 4 [reward] = & Gt; 7) [4] = & gt; Array ([number] => 70 [rank] => 5 [reward] => 5.5) [5] => Hey ([ Number] = & gt; 70 [rank] => 5 [reward] => 5.5))    

No comments:

Post a Comment