我正在用PHP开发一个项目。我想做的是每个月自己增加个数字(例如 500 )。有什么办法可以做到这一点?
答案 0 :(得分:0)
我不知道您的确切算法,但是猜测以下内容:
$start = new DateTime('2009-10-11');
$end = new DateTime('2010-12-23');
$diff = $end->diff($start);
$months = ($diff->y * 12) + $diff->m;
$rollup = 0;
var_dump("months: $months");
while ($months-- > 0) {
echo "rollup: $rollup".PHP_EOL;
$rollup += $rollup ?: 500;
}
var_dump("result: $rollup");
礼物:
string(10) "months: 14"
rollup: 0
rollup: 500
rollup: 1000
rollup: 2000
rollup: 4000
rollup: 8000
rollup: 16000
rollup: 32000
rollup: 64000
rollup: 128000
rollup: 256000
rollup: 512000
rollup: 1024000
rollup: 2048000
string(15) "result: 4096000"
答案 1 :(得分:0)
我做了一些假设:
500
值属于过去,我的意思是任何当前日期都将大于该初始日期$initialDate = strtotime("2018-12-01");
$years = (date("Y") - date("Y", $initialDate));
$number = 500 + $years*12
+ date("m") - date("m", $initialDate);
echo $number;