固定时间段之间的所有日期组合(PHP/循环)
这听起来像是一个愚蠢的问题,但我正在努力思考如何最好地解决它。
我有 2 个日期,比如说 2012 年 3 月 15 日到 2012 年 3 月 19 日。我需要提取从所有 4 天到 4 天的所有组合,输出如下(为简单起见,更改格式):
15, 16, 17, 18
15,16, 17
16, 17, 18
15, 16
16, 17
17, 18
15
16
17
18
我正在寻找最佳的循环方法,日期范围的长度会有所不同,格式不会相关,但它需要是 php 日期,我将从中提取所需的确切格式。我将使用每个日期集在每次迭代时执行代码,因此必须是日期/循环。
This sounds like a silly question but I am struggling to think of how best to tackle it.
I have 2 dates, lets say 15-03-2012 to 19-03-2012. I need to extract all combinations working down from all 4 days together to 4 individual days, output like this (formatting change for simplicity):
15, 16, 17, 18
15,16, 17
16, 17, 18
15, 16
16, 17
17, 18
15
16
17
18
I am looking for the best looping method, the date range will vary in length, the format isn't relevant but it needs to be php dates from which I will extract the exact format required. I will be using each date set to execute code at each iteration so has to be dates/loops.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建两个您拥有的值的 Date 对象,编写一个 while 循环,运行直到开始变量(您的开始日期)等于结束变量(您的结束日期),您应该完成。
Create two Date objects of the values you have, write a while loop that runs until the start variable (your start date) is equal to the end variable (your end date) and you should be done.
总体思路:
The general idea: