PHP实时错误?
看看这段代码,请告诉我,这段代码如何在周三完美运行,而不是在周二:PHP实时错误?,php,Php,看看这段代码,请告诉我,这段代码如何在周三完美运行,而不是在周二: <?php $current_time = strtotime('now'); if ($current_time > strtotime('tuesday this week 8:45pm') && $current_time < strtotime('tuesday this week 11:45pm')) { $background = 1; } if ($current_time &
<?php
$current_time = strtotime('now');
if ($current_time > strtotime('tuesday this week 8:45pm') && $current_time < strtotime('tuesday this week 11:45pm')) {
$background = 1;
}
if ($current_time > strtotime('wednesday this week 8:45pm') && $current_time < strtotime('wednesday this week 11:45pm')) {
$background = 1;
}
else{
$background = 0;
}
?>
<script>
var backday = <?php echo json_encode($background); ?>;
</script>
var backday=;
对于星期二,它返回0,但是对于星期三,它返回1,这是应该的。为什么? 您的逻辑有错误。第一个条件可能会返回1,但随后会遇到第二个条件。如果第二个条件中的第一个If为false,则无论在第一个条件中设置了什么,它都会在else块中将变量设置为0。您需要将您的第二个if语句设置为else if,如下所示:
if ($current_time > strtotime('tuesday this week 8:45pm') && $current_time < strtotime('tuesday this week 11:45pm')) {
$background = 1;
}
else if ($current_time > strtotime('wednesday this week 8:45pm') && $current_time < strtotime('wednesday this week 11:45pm')) {
$background = 1;
}
else{
$background = 0;
}
if($current_time>strottime($本周星期二晚上8:45))&&$current_timestrottime('本周星期三晚上8:45')&&$current_time
您的逻辑有错误。第一个条件可能会返回1,但随后会遇到第二个条件。如果第二个条件中的第一个If为false,则无论在第一个条件中设置了什么,它都会在else块中将变量设置为0。您需要将您的第二个if语句设置为else if,如下所示:
if ($current_time > strtotime('tuesday this week 8:45pm') && $current_time < strtotime('tuesday this week 11:45pm')) {
$background = 1;
}
else if ($current_time > strtotime('wednesday this week 8:45pm') && $current_time < strtotime('wednesday this week 11:45pm')) {
$background = 1;
}
else{
$background = 0;
}
if($current_time>strottime($本周星期二晚上8:45))&&$current_timestrottime('本周星期三晚上8:45')&&$current_time
取决于您设置的时区。对我来说,它们都应该返回0。我想你的意思是,在星期二两次之间执行此操作时不起作用,但在星期三两次之间执行此操作时确实起作用?运行此操作时,服务器(不是本地)的时间是多少?取决于您设置的时区。对我来说,它们都应该返回0。我想你的意思是,在星期二两次之间执行时,它不起作用,但在星期三两次之间执行时,它确实起作用?运行此操作时,服务器(不是本地)的时间是多少?