Golf league payout to six finishing positions
<p>I have a golf league of 40 individuals. We all throw money in a pot and pay out the first 6 places based on final score. </p>

<p>If there were no ties the pay out would be simple but often we have, for example, 2 people tied for first place, 3 people tied for second, 1 person alone in third, etc. The variations seem endless. </p>

<p>I've been trying to automate the calculated payouts for each place using PHP but have not been successful. Any suggestions, help, or pointing in the right direction would be much appreciated. I noticed that someone else tried to ask a similar question on this site but was not successful in framing the question. I'll try to do a better job.</p>

<p>Here is some data I've been playing around with:</p>

<pre><code>$playerNumber=40;
$totalPoints=100;
</code></pre>

<p>Payouts:</p>

<pre><code>$pointsFirst=0.6*$totalPoints;
$pointsSecond=0.2*$totalPoints;
$pointsThird=0.15*$totalPoints;
$pointsFourth=0.03*$totalPoints;
$pointsFifth=0.02*$totalPoints;
$pointsSixth=0.01*$totalPoints;
</code></pre>

<p>For the example given above and to pay out six places, we would calculate the payouts as follows:
If two people are tied for first place, we add first and second place points and divide by two.
If three people are tied for second place, we add third, fourth and fifth place points and divide by three.
If one person is alone in third, this person would win sixth place points.</p>

<p>I can count the number of players who are in or tied for a certain place.</p>

<pre><code>$countFirst=2;
$countSecond=3;
$countThird=1;
$countFourth=2;
$countFifth=1;
$countSixth=2;
</code></pre>

<p>In this example the player scores would be 72, 72, 73, 73, 73, 74, 75, 75, 76, 77, 77.</p>

<p>At first I thought this was an application for nested arrays. Then I thought perhaps using arrays, array slice, etc, may be a way to go. Each time I end up in the woods. I'm not seeing the logic. </p>

<p>I have used conditional statements for paying out three places but to pay out six places with this method puts me deep in the woods.</p>

<p>Example of payout to three places using conditional statements:</p>

<pre><code>$pointsFirst=0.5*$totalPoints;
$pointsSecond=0.3*$totalPoints;
$pointsThird=0.2*$totalPoints;          

if($countFirst&gt;2) {  

    $ptsA=round($totalPoints/$countFirst,2);
}
elseif($countFirst==2) {

    $ptsA=round(($pointsFirst+$pointsSecond)/2,2);

    if($countSecond&gt;1) { 

        $ptsB=round($pointsThird/$countSecond,2);                   
    }
    elseif($countSecond==1) {

        $ptsB=round($pointsThird,2);                    
    }
}
elseif($countFirst==1) { 

    $ptsA=round($pointsFirst,2);

    if($countSecond&gt;1) {

        $ptsB=round(($pointsSecond+$pointsThird)/2,2);                  
    }
    elseif($countSecond==1) {

        $ptsB=round($pointsSecond,2);                   

        if($countThird&gt;1) {

            $ptsC=round($pointsThird/$countThird,2);                        
        }
        elseif($countThird==1) {

            $ptsC=round($pointsThird,2);                        
        }
    }
}
</code></pre>

<p>I hope I have been clear in my request. I'll be glad to clarify anything. If anyone has any ideas on how to efficiently automate a payout calculation to six places I will be eternally grateful. Thank-you! Mike</p>

<p>Per request:</p>

<pre><code>$scores=array();
$scores[0]=72;
$scores[1]=72;
$scores[2]=73;
$scores[3]=73;
$scores[4]=73;
$scores[5]=74;
$scores[6]=75;
$scores[7]=75;
$scores[8]=76;
$scores[9]=77;
$scores[10]=77;

$payout=array();
$payout[0]=0.6*$totalPoints;
$payout[1]=0.2*$totalPoints;
$payout[2]=0.15*$totalPoints;
$payout[3]=0.03*$totalPoints;
$payout[4]=0.02*$totalPoints;
$payout[5]=0.01*$totalPoints;

$countScores=array();
$countScores[0]=$countFirst;
$countScores[1]=$countSecond;
$countScores[2]=$countThird;
$countScores[3]=$countFourth;
$countScores[4]=$countFifth;
$countScores[5]=$countSixth;
</code></pre>
