如果符合条件,下面的代码中有什么更好的方法可以为变量$timestop
和$time_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;
答案 0 :(得分:1)
不,覆盖变量没有问题,这是日常工作。 你甚至没有覆盖任何其他类型,你只是重置为另一个整数值。
它甚至更好,因为你不会浪费任何额外的内存空间(当然不是很高,但是要大规模地考虑它)。