即時學習PHP,我無法獲得這段代碼的工作,我剛剛開始進入php,並不能弄清楚這一點。在線驗證器報告沒有發現問題,但它爲我設置了一個無限循環。有人能告訴我爲什麼$ eggUsage沒有從$蛋中減去。php從變量中減去一個變量以獲取值
謝謝:-)
<?php
$eggs = 12;
$eggUsage = 0;
while($eggs - $eggUsage > 0) {
$eggUsage = rand(0, 1, 2, 3, 4);
$eggs = $eggs - $eggUsage;
echo "You have {$eggs} left";
}
if ($eggs < 4) {
$eggUsage = rand(0, 1, 2, 3, 4);
$eggs == $eggs - $eggUsage;
echo "You are almost out. BUY EGGS!";
}
echo "<p>Congratulations, you are out of eggs.</p>"
?>
'$ eggs = $ eggs - $ eggUsage;' – 2015-04-01 15:11:14