php从两个日期之间的每1年开始获取日期(php get date from now every 1 year between two dates)

编程入门 行业动态 更新时间:2024-10-13 04:18:37
php从两个日期之间的每1年开始获取日期(php get date from now every 1 year between two dates)

我试图每隔1年获得一次日期或两个日期之间的任何可变间隔。 我的约会例子如下。 它似乎永远运行,我不能让它工作,它最终没有打印任何东西。

$currentDate = '2014-04-15'; $endDate = '2018-04-15'; $reminder = '+1 year'; $dateArray = array(); while($currentDate <= $endDate){ $currentDate = date('Y-m-d', strtotime($reminder, strtotime($currentDate))); array_push($dateArray, $currentDate); } print_r($dateArray);

I'm trying to get the date every 1 year or any variable interval between two dates. My dates examples are as follows. It just seems to run forever and I cant make it work and it doesn't print anything out at the end.

$currentDate = '2014-04-15'; $endDate = '2018-04-15'; $reminder = '+1 year'; $dateArray = array(); while($currentDate <= $endDate){ $currentDate = date('Y-m-d', strtotime($reminder, strtotime($currentDate))); array_push($dateArray, $currentDate); } print_r($dateArray);

最满意答案

请更换

$dateArray = array_push($dateArray, $currentDate);

array_push($dateArray, $currentDate);

因为array_push,返回布尔值,下次你调用这个函数,它会尝试将字符串存储在int / boolean类型中并导致错误。

please change

$dateArray = array_push($dateArray, $currentDate);

to

array_push($dateArray, $currentDate);

Because array_push, returns boolean and next time, you call this function, it tries to store string in the int/boolean type and cause error.

更多推荐

本文发布于:2023-07-18 04:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154816.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   两个   php   dates   year

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!