我试图让它显示正确的东西。当我运行它时,酒店费用保持在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