PHP x 天后更改日期变量

PHP Change date variable after x days

我想在 x 天后更改日期变量

例如:

今天是21.12.16 - $date = '23.12.16'

明天是22.12.16 - $date = '23.12.16'

什么时候23.12.16 - $date = '25.12.16'

她是我目前得到的密码。希望这会有意义

   $date            = "2016-12-21"; //** will describe this lower
   $days_passed = date_create()->diff(date_create($date))->days;
if ($days_passed >= 2){
    $new_date = date('d.m.y', strtotime("+2 days"));
} else{
    $new_date = $date;
}

如果我只想做一次就可以了

**我需要每 2 天更改一次此变量。我知道我可以将它写入数据库或 .txt。但是确实有一种方法可以做到这一点 php

P.S。抱歉我的英语不好。

这是我想出的:

$date           = '2016-12-01';  //Your script start date, you wont need to change this anymore
$everyxdate     = 10; // once x days to add x to $date
$days_passed    = date_create()->diff(date_create($date))->days; // passed days from start of script $date

$mod_dates = (int)($days_passed / $everyxdate); // count how much cycles have passed
$daystoadd = $mod_dates * $everyxdate + $everyxdate;  // count how much days we need to add
$newdate = strtotime ("+$daystoadd day" , strtotime ( $date ) ) ; // Add needed day count to starting $date 
$newdate = date ( 'd.m.y' , $newdate ); // Format date the way you want

希望这会帮助那些和我有同样任务的人。