This article mainly introduces how to solve the PHP countdown 0 situation, the case analysis of the PHP Countdown program appeared-0 reasons and the corresponding solution, with a certain reference value, the need for friends can refer to the next
Specific as follows:
question: Today there is feedback, said the countdown appeared-0 days of the situation, I looked at the program, the trough, how did not test to
The reason is that PHP logic is judged in -0 > 0
Analysis: code with errors posted
$starttime = 1362585600;//3.7 early $nowtime = 1362618921;//3.7 Morning $off = Ceil (($starttime-$nowtime)/86400);// Countdown if ($off < 0) { $off = 0;} $b = $starttime-$nowtime; $c = $b/86400; $d = Ceil ($c); Var_dump (Array (' Start-now ' + $b), array (' float_day ' = = $c), Array (' int_day ' = $d), array (' off ' = $off)), if ( -0 < 0) { echo '-0 < 0 ';} else { echo '-0 > 0 ';}
Output:
Array ' start-now ' = = Int-33321array ' float_day ' + float-0.385659722222array ' int_day ' = = Float-0array ' off ' = > float-0-0 > 0
Process:
When the start time and the current time are the same day, the upper calculation process is due to -0 > 0 so that the case of off =-0 appears
Improved:
$starttime = 1362585600;//3.7 early $nowtime = 1362618921;//3.7 Morning if ($starttime-$nowtime) < 0) { $off = 0;} else { $off = ceil (($starttime-$nowtime)/86400);}
Summary: The above is the entire content of this article, I hope to be able to help you learn.