title: I need to calculate a golf score using a PHP function, but I am unable to come up with the proper equation
body: <p>I am writing a function to figure out a players score for a golf game (Not a standard round of golf, but a custom game).</p>
  
  <p>This figures in the actual score, the hole's handicap and the player's handicap.</p>
  
  <p>For example: If the player shoots a 6, and that player's handicap is 6 and the holes handicap is a 4 the player would get a score of 5 on the hole. Here is why:</p>
  
  <p>If the player's handicap is less than or equal to the hole's handicap they receive -1 point from their actual score. On an 18 hole golf course, holes have a handicap ranging from 1 to 18. So if a player has a handicap of 18 they will receive -1 point from the score of each hole. So as long as the player's handicap is 18 or less, this is easy for me to figure out. The problem I am having is how to calculate this if a player's handicap is over 18. A player could have a handicap anywhere from 1 to 99.</p>
  
  <p>So if a player's handicap was 21 they would receive -1 point on all 18 holes. Then on the holes who's handicaps are 1, 2, &amp; 3 they would receive an additional -1 point on those holes as well. So if the player's handicap was 36, they would have -2 points of their score for all holes.</p>
  
  <p>This is the function I have so far:</p>
  
  <pre><code>function handicapCalc($hole,$player,$score){
      if($player &lt;= 18){
          if($hole &lt;= $player){
              $finalScore=$score-1;
          }else{
              $finalScore=$score;
          }
      }else{
          //FIGURE SCORE IF HANDICAP IS LARGER THEN 18
      }
      return $finalScore;
  }
  </code></pre>
  
  <p>$hole is the variable of the hole's handicap, $player is the player's handicap &amp; $score is the player's score.</p>
  
  <p>I need to figure out a calculation to allow for a handicap over 18.</p>
  
  <p>Thank you for any help you may be able to offer.</p>
  
  <hr>
  
  <p><strong>EDIT [SOLVED]</strong></p>
  
  <pre><code>function handicapCalc($holeHandicap,$playerHandicap,$holes,$score){
      $perHoleHandicap=floor($playerHandicap/$holes);
      $leftOvers=$playerHandicap % $holes;
  
      if($perHoleHandicap &gt;= 1){
          $firstScore=$score-$perHoleHandicap;
          if($leftOvers &gt;= $holeHandicap){
              $finalScore=$firstScore-1;
          }else{
              $finalScore=$firstScore;
          }
      }else{
          if($perHoleHandicap &gt;= $holeHandicap){
              $finalScore=$score-1;
          }else{
              $finalScore=$score;
          }
      }
      return $finalScore;
  }
  </code></pre>