在选择器选项中选择两个行星A和B来测量距离。
例如:
if (($planetA == "Nova Terra" || $planetB == "Nova Iaponia") && ($planetA == "Nova Iaponia" || $planetB == "Nova Terra"))
{
echo "From $planetA to $planet B: 290 parsecs";
}
else if (($planetA == "Nova Terra" || $planetB == "Novo Mars") && ($planetA == "Novo Mars" || $planetB == "Nova Terra"))
{
echo "From $planetA to $planet B: 230 parsecs";
}
您从Nova Terra到Nova Iaponia或从Nova Iaponia到Nova Terra"阅读。 To =和。
这类似于:
if ($planetA == "Nova Terra" || $planetB == "Nova Iaponia")
{
echo "From $planetA to $planet B: 290 parsecs";
}
else if ($planetA == "Nova Iaponia" || $planetB == "Nova Terra")
{
echo "From $planetA to $planet B: 290 parsecs";
}
else if ($planetA == "Nova Terra" || $planetB == "Novo Mars")
{
echo "From $planetA to $planet B: 230 parsecs";
}
else if ($planetA == "Novo Mars" || $planetB == "Nova Terra")
{
echo "From $planetA to $planet B: 230 parsecs";
}
答案 0 :(得分:4)
您只需要交换逻辑运算符即可获得所需的结果
if (($planetA == "Nova Terra" && $planetB == "Nova Iaponia") || ($planetA == "Nova Iaponia" && $planetB == "Nova Terra"))
{
echo "From $planetA to $planet B: 290 parsecs";
}
else if (($planetA == "Nova Terra" && $planetB == "Novo Mars") || ($planetA == "Novo Mars" && $planetB == "Nova Terra"))
{
echo "From $planetA to $planet B: 230 parsecs";
}