0

下面的代码中向变量添加新值$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;
4

1 回答 1

1

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

甚至更好,因为你不会浪费任何额外的内存空间(当然不高,但大体上想想)。

于 2012-06-17T01:18:35.317 回答