我正在做一个 PHP 任务,我基本上已经完成了所有工作。然而,由于我对 PHP 的了解有限,代码看起来有点太简单了。它的作用是根据输入的小时数和工资计算总工资。
你们有什么建议可以让它更好/更短,更高效吗?
<?php
$hours = $_GET ["hours"];
$wages = $_GET ["wages"];
if (empty($hours))
{
echo "Amount of hours worked is required. <br />";
}
if (empty($wages))
{
echo "Employee wage is required. <br />";
}
if (!is_numeric($hours) and ($wages) && !empty ($hours) and ($wages))
{
echo "Please enter numeric numbers only. <br />";
}
if (!empty($hours) and ($wages))
{
if (is_numeric($hours) and ($wages))
{
if ($hours <= 40)
{
$totalPay = $hours * $wages;
echo "Your total pay is $ $totalPay";
}
if ($hours > 40)
{
$totalPay = ((40 * $wages) + (($hours - 40) * $wages * 1.5));
echo "Your total pay is $ $totalPay";
}
}
}
else
{
echo "Unable to calculate total pay.";
}
?>