如何在PHP中传递一天后递增变量的变量

时间:2017-11-08 13:21:01

标签: javascript php

我需要根据一天的数量增加变量。例如

就像$ day =“120”; 然后明天$ day变量是121。

1 个答案:

答案 0 :(得分:1)

如果您知道起始计数是什么,以及您何时开始计算,则可以执行此操作。如果您预先掌握了这两条信息,那么您将不再需要数据库。

<?php
$start_count = 120; // Original starting position (counter).
$start_time  = strtotime('2017-11-08 00:00:00'); // Original start time.
                                                 // Format is YYYY-MM-DD HH:MM:SS

$now  = time(); // Time now, in seconds.
$diff = $now - $start_time; // Difference, in seconds.

$days          = floor($diff / 86400); // Divide by seconds in one day.
$current_count = $start_count + $days; // Start count + days since start time.