【发布时间】:2018-03-14 04:02:54
【问题描述】:
我的 if 条件似乎有问题。 每当我输入过期超过 31 天的许可证时,它就会进入许可证过期日期大于 31 天的条件,它将给出一个绿色圆圈和绿色文本。 它会将其读取为已过期,并且直到 31 天才会过期,并带有红色和绿色的圆圈和文字。
这是一个sn-p。
$exp = strtotime($exp_date);
$td = strtotime($today_date);
$diff= $td -$exp;
$x = abs(floor($diff/ (60 * 60 * 24)));
$alertdays = ""; //expired
$alertdays1 = ""; //less than 30 days before expiry
$alertdays2 = ""; //more than 30 days
$statusexp = ""; //expired
$status = ""; //less than 30 days
$status1 = ""; //more than 30 days
$daysexp = ""; //days expired
if($td > $exp)
{
$statusexp = '<i class="fa fa-circle" style="font-size:30px; color:red;"></i>';
}
if($diff < 0){
$status = '<i class="fa fa-circle" style="font-size:30px; color:orange;"></i>';
}
if($diff <= 30) {
$alertdays1 = $x. "";
}
if($x >= 31){
$alertdays1 = "";
$alertdays2 = $x. "";
$status ='<i class="fa fa-circle" style="font-size:30px; color:green;"></i>';
}
if($td > $exp){
$alertdays ="Expired";
$daysexp = " - " . $x;
}
【问题讨论】:
-
请提供一小部分测试用例(每个测试用例两个日期)以及每个测试用例的预期输出。 ...请不要图片。
-
如果您要有条件地回显一个空字符串,请不要打扰。只需完全删除 else 组件。
-
这个任务你肯定不需要这么多变量吧?
标签: php date comparison conditional