Advertisement
Danack

Graph generating compound interest

Sep 27th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. <?php
  2.  
  3. $graphingFunction = function($months, $paymentPerMonth) {
  4.  
  5. $addPaymentAndInterest = function ($payment) use ($paymentPerMonth) {
  6. static $last = 0;
  7. $interestRate = (rand(0, 100) / 20) / 100;
  8. $last = $paymentPerMonth + ($last * (1 + $interestRate));
  9. return $last;
  10. };
  11.  
  12. return array_map($addPaymentAndInterest, array_fill(0, $months, $paymentPerMonth));
  13. };
  14.  
  15. $graph = $graphingFunction(50, 100);
  16.  
  17. var_dump($graph);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement