发现错误
时间:2008-10-30
来源:互联网
递归函数的例子和遍历数组的5-1的代码错误
递归的代码
<?php
function amortizationTable($paymentNum,$periodicPayment, $balance,
$monthlyInterest){
$paymentInterest = round($balance + $monthlyInterest,2);
$paymentPrincipal = round($periodicPayment - $paymentInterest,2);
$newBalance = round($balance - $paymentPrincipal,2);
print "<tr>
<td>$paymentNum</td>
<td>\$".number_format($balance,2)."</td>
<td>\$".number_format($periodicPayment,2)."</td>
<td>\$".number_format($paymentInterest,2)."</td>
<td>\$".number_format($paymentPrincipal,2)."</td>
</td>";
# if balance not yet zero, recursively call amortizationTable()
if ($newBalance > 0){
$paymentNum++;
amortizationTable($paymentNum, $periodicPayment,$newBalance,
$monthlyInterest);
} else {
exit;
}
}#end amotizationTable()
?>
<?php
# Loan balance
$balance = 10.00;
# Loan interest rate
$interestRace = .0575;
# Monthly interest rate
$monthlyInterest = .0575 / 12;
# Term length of the loan, in years.
$termlength = 30;
# Nunmeber of payments per years.
$paymentsPerYear = 12;
# Payment iteration
$paymentNumber = 1;
# Perform preliminary calculations
$totalPayments = $termlength * $paymentsPerYear;
$intCalc = 1 + $interestRate / $paymentsPerYear;
$periodicPayment = $balance * pow($intCalc,$totalPayments)*($intCalc-1)/(pow($intCalc,$totalPayments)-1);
$periodicPayment = round($periodicPayment,2);
# Create table
echo "<table width='50%' align='center' border='1'>";
print "<tr>
<th>payment Number</th><th>Balance</th>
<th>Payment</th><th>interest</th><th>Principal</th>
</tr>";
# Call rescursive function
amortizationTable($paymentNumber,$periodicPayment,$balance,$monthlyInterest);
# Close table
print "</table>";
?>
遍历数组 array_walk() 的代码
表单5-1[code]
<form action="submitdata.php" method="post">
<p>
Provide up to six keywords that you believe best describle
the state in which you live:
</p>
<p>Keyword 1:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 2:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 3:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 4:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 5:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 6:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p><input type="submit" name="button" id="button" value="submit!" /></p>
</form>
[/code]submitdata.php
[php]<?php
function sanitize_data(&$value,$key){
$value = strip_tags($value);
}
array_walk($_POST['keyword'],"sanitze_data");
?>[/php]
运行错误显示:
Warning: array_walk() [function.array-walk]: Unable to call sanitze_data() - function does not exist in D:\ComsenzEXP\wwwroot\ceshi\submitdata.php on line 6
递归的代码
<?php
function amortizationTable($paymentNum,$periodicPayment, $balance,
$monthlyInterest){
$paymentInterest = round($balance + $monthlyInterest,2);
$paymentPrincipal = round($periodicPayment - $paymentInterest,2);
$newBalance = round($balance - $paymentPrincipal,2);
print "<tr>
<td>$paymentNum</td>
<td>\$".number_format($balance,2)."</td>
<td>\$".number_format($periodicPayment,2)."</td>
<td>\$".number_format($paymentInterest,2)."</td>
<td>\$".number_format($paymentPrincipal,2)."</td>
</td>";
# if balance not yet zero, recursively call amortizationTable()
if ($newBalance > 0){
$paymentNum++;
amortizationTable($paymentNum, $periodicPayment,$newBalance,
$monthlyInterest);
} else {
exit;
}
}#end amotizationTable()
?>
<?php
# Loan balance
$balance = 10.00;
# Loan interest rate
$interestRace = .0575;
# Monthly interest rate
$monthlyInterest = .0575 / 12;
# Term length of the loan, in years.
$termlength = 30;
# Nunmeber of payments per years.
$paymentsPerYear = 12;
# Payment iteration
$paymentNumber = 1;
# Perform preliminary calculations
$totalPayments = $termlength * $paymentsPerYear;
$intCalc = 1 + $interestRate / $paymentsPerYear;
$periodicPayment = $balance * pow($intCalc,$totalPayments)*($intCalc-1)/(pow($intCalc,$totalPayments)-1);
$periodicPayment = round($periodicPayment,2);
# Create table
echo "<table width='50%' align='center' border='1'>";
print "<tr>
<th>payment Number</th><th>Balance</th>
<th>Payment</th><th>interest</th><th>Principal</th>
</tr>";
# Call rescursive function
amortizationTable($paymentNumber,$periodicPayment,$balance,$monthlyInterest);
# Close table
print "</table>";
?>
遍历数组 array_walk() 的代码
表单5-1[code]
<form action="submitdata.php" method="post">
<p>
Provide up to six keywords that you believe best describle
the state in which you live:
</p>
<p>Keyword 1:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 2:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 3:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 4:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 5:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p>Keyword 6:<br />
<input type="text" name="keyword[]" size="20" maxlength="20" value="" /></p>
<p><input type="submit" name="button" id="button" value="submit!" /></p>
</form>
[/code]submitdata.php
[php]<?php
function sanitize_data(&$value,$key){
$value = strip_tags($value);
}
array_walk($_POST['keyword'],"sanitze_data");
?>[/php]
运行错误显示:
Warning: array_walk() [function.array-walk]: Unable to call sanitze_data() - function does not exist in D:\ComsenzEXP\wwwroot\ceshi\submitdata.php on line 6
作者: 银河王子 发布时间: 2008-10-30

书中错误不止这点……
作者: To豆泥_ 发布时间: 2008-11-03
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28