-2
我正在從事一項PHP任務,基本上我做的一切都很好。然而,由於我對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.";
}
?>
我認爲這個問題將是對[codereview.se] :) –
使用正確的縮進更合適的更簡單,它會使它看起來好很多 – aurbano
簡單有什麼問題?哦,對,[KISS](https://en.wikipedia.org/wiki/KISS_principle)現在的意思是「保持超級複雜」。 – Oswald