How to solve the PHP countdown-0 Scenario

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.