code: public static function ISPMT(...$args)
      {
          // Return value
          $returnValue = 0;
  
          // Get the parameters
          $aArgs = Functions::flattenArray($args);
          $interestRate = array_shift($aArgs);
          $period = array_shift($aArgs);
          $numberPeriods = array_shift($aArgs);
          $principleRemaining = array_shift($aArgs);
  
          // Calculate
          $principlePayment = ($principleRemaining * 1.0) / ($numberPeriods * 1.0);
          for ($i = 0; $i <= $period; ++$i) {
              $returnValue = $interestRate * $principleRemaining * -1;
              $principleRemaining -= $principlePayment;
              // principle needs to be 0 after the last payment, don't let floating point screw it up
              if ($i == $numberPeriods) {
                  $returnValue = 0;
              }
          }
  
          return $returnValue;
      }
docs: ISPMT.
  
  Returns the interest payment for an investment based on an interest rate and a constant payment schedule.
  
  Excel Function:
  =ISPMT(interest_rate, period, number_payments, PV)
  
  interest_rate is the interest rate for the investment
  
  period is the period to calculate the interest rate.  It must be betweeen 1 and number_payments.
  
  number_payments is the number of payments for the annuity
  
  PV is the loan amount or present value of the payments