02c04-3.php

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

PHP
50
字号
<?phpob_start();require '02c04-1.php';ob_end_clean();// Let's calculate and output a table of values showing a monthly balance //  of a credit card assuming we start with a $5000 debt, have a 9.2% rate,//  it is compounded monthly, and we make $200 payments a month$value = 5000;$rate = .092;$payment = 200;// Begin our output:echo "<style>td { border: 1px solid black; }</style><table><tr><th>Month</th><th>Initial Value</th><th>Interest</th><th>Payment</th><th>End of Month Balance</th><th>Cumulative Payments Made</th></tr>\n";// Until the value is 0 or less, loop:$month = 1;$cumulative = 0;while ($value > 0) {    // Calculate the interest that would be applied this month:    $interest = calc_simple_interest($value, $rate, 1/12);        // Calculate the new principal    $newvalue = $value + $interest;        // Determine if the payment would be too much, and adjust accordingly:    $payment = ($payment > $newvalue) ? $newvalue : $payment;        // Add up the cumulative payments made:    $cumulative += $payment;    // Now determine the final value:    $finalvalue = $newvalue - $payment;            // Echo out the values:    echo '<tr><td>', $month++, "</td><td>{$value}</td><td>{$interest}</td><td>{$payment}</td><td>{$finalvalue}</td><td>{$cumulative}</td></tr>\n";        // Now reset the value to this month's end, and repeat:    $value = $finalvalue;}// Finish up our display, and exit ... This will end up displaying a table//  showing that it will take 28 months to pay this debt off, and that you//  will end up paying $5572.15 in total.echo '</table>';?>

⌨️ 快捷键说明

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