显示结果的第一个 IF 语句的结果。我想使用两个输出值来操作第二个IF语句,以获取的值,或者在任何给定时间只有一个返回值。我尝试过在每个 if 或 ifelse 语句中使用,但无济于事。有人可以提供帮助吗?$loadedWeightUSTons$emptyWeight$loadWeightUSTons or $emptyWeight第一中频统计if ($loadWeightUSTons == 0) { echo "E"; }else { echo "L"; } echo "</td>"; echo "<td>"; if ($loadWeightUSTons == 0){ $emptyWeight = "Not Found!"; foreach($railunit->railUnit as $ru) { if((string)$ru->rvXMLfilename == $rvXMLfilename){ $emptyWeight = (string)$ru->unitWeight; } } echo $emptyWeight; }else{ echo $loadWeightUSTons; }第二中频统计if ($loadWeightUSTons <= 10) { echo "X"; } elseif ($loadWeightUSTons <= 20){ echo "XX"; } elseif ($loadWeightUSTons <= 30){ echo "XXX"; } elseif ($loadWeightUSTons <= 40){ echo "XXXX"; } elseif ($loadWeightUSTons <= 50){ echo "XXXXX"; } elseif ($loadWeightUSTons <= 60){ echo "XXXXXX"; } elseif ($loadWeightUSTons <= 70){ echo "XXXXXXX"; } elseif ($loadWeightUSTons <= 80){ echo "XXXXXXX"; } elseif ($loadWeightUSTons <= 90){ echo "XXXXXXXX"; } elseif ($loadWeightUSTons <= 100){ echo "XXXXXXXXX"; } elseif ($loadWeightUSTons <= 110){ echo "XXXXXXXXXX"; } elseif ($loadWeightUSTons <= 120){ echo "XXXXXXXXXXX"; } elseif ($loadWeightUSTons <= 130){ echo "XXXXXXXXXXXX"; } elseif ($loadWeightUSTons <= 140){ echo "XXXXXXXXXXXXX"; } elseif ($loadWeightUSTons <= 150){ echo "XXXXXXXXXXXXXX"; } else{ echo "Error!"; }
2 回答
慕娘9325324
TA贡献1783条经验 获得超4个赞
我最终接受了上面的建议,并将其应用于下面看到的IF语句。它取代了笨重的声明。ifelseif
if ($loadWeightUSTons == 0){
echo str_repeat('X', ceil($emptyWeight/10));
}else{
echo str_repeat('X', ceil($loadWeightUSTons/10));
}
蓝山帝景
TA贡献1843条经验 获得超7个赞
if ($loadWeightUSTons > 150) {
echo "Error!";
} else {
echo str_repeat("X",ceil($loadWeightUSTons/10));
}
但我可能会建议只按原样输出数字。拥有这些并不比数字更能提供信息。这将带来更好的用户体验。特别是如果你将这个数字限制在150,并且你有像那里这样的长数字值。XXX1 234 567 890
- 2 回答
- 0 关注
- 89 浏览
添加回答
举报
0/150
提交
取消