我做的事情可能非常愚蠢,想知道我是否能让任何人指出我做错了什么。教我自己的PHP,并在这样做,我试图制作一个工资计算器。它给了我这些结果:
Your results:
29 years old earning
$205per day working
$5days a week at a
Your total earned money at age 65 is $0.
While your yearly income is
49200
显然,总赚来的钱数字不正确。 0不对。
这里是完整的代码
<?php
//get the values from the $_POST array
$age = $_POST['age'];
$days = $_POST['days'];
$pay = $_POST['pay'];
//calculate the total:
$howold = 65 - $age;
$retireageincome = $yearlyincome * $howold;
$yearlyincome = $pay * $days * 4 * 12;
//print out results
print "<p>Your results:<br>
<span class=\"number\">$age</span> years old earning <br>
$<span class=\"number\">$pay</span>per day working <br>
$<span class=\"number\">$days</span>days a week at a<br>
Your total earned money at age 65 is $<span class=\"number
\">$retireageincome</span>.<br>
While your yearly income is <br>
<span class=\"number\">$yearlyincome</span> </p>";
?>
</body>
</html>
答案 0 :(得分:1)
您尝试在$yearlyincome
的值已知之前使用$yearlyincome
。
命令顺序很重要。移动
$yearlyincome = $pay * $days * 4 * 12;
位于使用$yearlyincome
的行之前,您应该看到非0值。