<?php define( 'TERM_RATES_BY_YEAR', [ 2001 => ['term' => 24, 'rates' => [15.90, 19.90, 22.90, 22.90, 22.90]], 2002 => ['term' => 24, 'rates' => [15.90, 19.90, 22.90, 22.90, 22.90]], 2003 => ['term' => 24, 'rates' => [15.90, 19.90, 22.90, 22.90, 22.90]], 2004 => ['term' => 24, 'rates' => [15.90, 19.90, 22.90, 22.90, 22.90]], 2005 => ['term' => 24, 'rates' => [15.90, 19.90, 22.90, 22.90, 22.90]], 2006 => ['term' => 24, 'rates' => [15.90, 18.90, 21.90, 22.90, 22.90]], 2007 => ['term' => 36, 'rates' => [15.90, 18.90, 21.90, 22.90, 22.90]], 2008 => ['term' => 36, 'rates' => [14.90, 17.90, 21.90, 22.90, 22.90]], 2009 => ['term' => 36, 'rates' => [14.90, 17.90, 20.90, 20.90, 20.90]], 2010 => ['term' => 36, 'rates' => [14.90, 17.90, 20.90, 20.90, 20.90]], 2011 => ['term' => 42, 'rates' => [14.90, 16.90, 19.90, 19.90, 20.90]], 2012 => ['term' => 42, 'rates' => [12.90, 15.90, 18.90, 19.90, 19.90]], 2013 => ['term' => 42, 'rates' => [12.90, 15.90, 18.90, 18.90, 18.90]], 2014 => ['term' => 48, 'rates' => [11.90, 14.90, 17.90, 18.90, 18.90]], ] ); define('CREDIT_SCORE_MINIMUM_THRESHOLDS', [720, 610, 580, 530, 489]); /** @throws Exception */ function getRateIndexFromCreditScore(int $creditScore): ?int { foreach (CREDIT_SCORE_MINIMUM_THRESHOLDS as $rateIndex => $minThreshold) { if ($creditScore >= $minThreshold) { return $rateIndex; } } throw new Exception("Sorry, your credit score ($creditScore) does not qualify for financing"); } foreach (range(2000, 2015) as $year) { try { if (!isset(TERM_RATES_BY_YEAR[$year])) { throw new Exception("Sorry, your vehicle year ($year) does not qualify for financing"); } $score = rand(300, 850); $rateIndex = getRateIndexFromCreditScore($score); $outcome = sprintf( 'Vehicle Year: %d, Credit Score: %d, Term: %d, Rate: %.2f', $year, $score, TERM_RATES_BY_YEAR[$year]['term'], TERM_RATES_BY_YEAR[$year]['rates'][$rateIndex] ); } catch (Exception $e) { $outcome = $e->getMessage(); } echo "$outcome\n"; }
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`