02c04-5.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 62 行

PHP
62
字号
<?phpob_start();require '02c04-1.php';ob_end_clean();// A function to make a table of payments using the Rule of 78 for interest// a = the initial amount you are calculating from// r = the annual percentage rate// y = the number of years of the loanfunction create_payment_table($a, $r, $y) {	// First of all calculate the total interest & total Payment	$interest = calc_simple_interest($a, $r, $y);	$payment = $a + $interest;	// Also calculate what the monthly payment will be:	$monthly = $payment / ($y * 12);		// Echo these out:	echo "Total Payment = {$payment}<br />Total Interest = {$interest}<br />Monthly Payments = {$monthly}<br />";		// Now calculate what the rule of 78 number will be:	$rule78 = array_sum(range(1, ($y * 12)));		// Begin our output:	echo "<style>td { border: 1px solid black; }</style><table><tr><th>Month</th><th>Interest</th><th>Principal</th><th>Equity</th></tr>\n";	// Now loop through all months, backwards	$equity = 0;	for ($m = ($y * 12); $m > 0; $m--) {		// Calculate the actual month number:		$num = abs($m - ($y * 12) - 1);				// Calculate the interest, principal & equity:		$int = $interest * ($m/$rule78);		$prin = $monthly - $int;		$equity += $prin;		// Now echo all that out		echo "<tr><td>{$num}</td><td>{$int}</td><td>{$prin}</td><td>{$equity}</td></tr>\n";	}		// Close off our table and exit	echo '</table>';}// Now make the table for a $250,000, 15 year mortgage at 5.5% interest// Will begin with:// Total Payment = 456250// Total Interest = 206250// Monthly Payments = 2534.7222222222// Month	Interest		  Principal			Equity// 1	    2279.0055248619	  255.71669736034	255.71669736034// 2	    2266.3443830571	  268.37783916513	524.09453652548create_payment_table(250000, .055, 15);?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?