+ -
当前位置:首页 → 问答吧 → 发现错误

发现错误

时间: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

作者: 银河王子   发布时间: 2008-10-30

我也是在这错误了  

书中错误不止这点……

作者: To豆泥_   发布时间: 2008-11-03