我試圖讓它顯示正確的東西。當我運行它時,酒店費用保持在960美元,如果我選擇開羅,它將顯示$ 0的航空公司門票,而酒店的價格爲960美元。其他人工作正常,但不會改變從960美元的酒店成本。這個IF聲明有什麼問題
if ($destination == "Barcelona")
$airFare = 875;
$hotel = 85 * $numNights;
if ($destination == "Cairo")
$airfare = 950;
$hotel = 98 * $numNights;
if ($destination == "Rome")
$airFare = 875;
$hotel= 110 * $numNights;
if ($destination == "Santiago")
$airFare = 820;
$hotel = 85 * $numNights;
if ($destination == "Tokyo")
$airFare = 1575;
$perNight = 240;
$tickets = $numTravelers * $airFare;
$hotel = $numTravelers * $numNights * $perNight;
$totalCost = $tickets + $hotel;
print("<p>Destination: $destination<br />");
print("Number of people: $numTravelers<br />");
print("Number of nights: $numNights<br />");
print("Airline Tickets: $".number_format($tickets, 2)."<br />");
print("Hotel Charges: $".number_format($hotel, 2)."</p>");
print("<p><strong>TOTAL COST: $".number_format($totalCost, 2)."</strong></p>");
使用{}擋住代碼,如果你不使用它們只剩下一行會if語句 – Emz