若满足条件,php将新值赋给变量

若满足条件,php将新值赋给变量,php,variables,if-statement,Php,Variables,If Statement,如果满足条件,下面的代码中有什么更好的方法向变量$timestop和$time\u diff添加新值 //Calculates difference in time using 24h format $timestart = strtotime("14:00:00"); $timestop = strtotime("07:00:00"); //if smaller value, it must end next day and meets the condition below $time_

如果满足条件,下面的代码中有什么更好的方法向变量
$timestop
$time\u diff
添加新值

//Calculates difference in time using 24h format

$timestart = strtotime("14:00:00");
$timestop = strtotime("07:00:00"); //if smaller value, it must end next day and meets the condition below

$time_diff = $timestop - $timestart; //elapsed time

if ($time_diff < 0 || $time_diff == 0) //if result is negative value, $timestop ends next day
{
   $timestop = strtotime( '+1 day' , strtotime("07:00:00") ); //+ 1 day changes timestamp
}

/* UPDATED */

$time_diff = $timestop - $timestart; //added again

echo $time_diff;
//使用24小时格式计算时间差
$timestart=strottime(“14:00:00”);
$timestop=strottime(“07:00:00”)//如果值较小,则必须在第二天结束,并满足以下条件
$time_diff=$timestop-$timestart//经过的时间
如果($time_diff<0 | |$time_diff==0)//如果结果为负值,$timestop将在第二天结束
{
$timestop=strottime(“+1天”,strottime(“07:00:00”);//+1天更改时间戳
}
/*更新*/
$time_diff=$timestop-$timestart//又加上
echo$time_diff;

不,覆盖变量没有问题,这是日常工作。 您甚至没有在任何其他类型中覆盖,您只是重置为另一个整数值


它甚至更好,因为您不会浪费任何额外的内存空间(当然不是很高,但要大规模地考虑)。

如果变量没有更新,则不满足
If
语句中的条件。好的,如果您添加一天,时间是一样的。任何时间+24小时都是相同的时间。在if:133999200之前,在if:1339995600之后。当然它会更新。为什么不使用
if($time\u diff)尝试使用类。新的方式:)