在日期时间数组中查找下一个事件
我有以下数组,由日期时间和事件组成。我希望返回今天的下一个活动。例如:如果今天的日期是 2010 年 11 月 19 日,则返回“足球比赛”。
实现这一结果的最佳方法是什么?
非常感谢。
Array(
[1] => Array
(
[start] => 20101113T100000Z
[event] => Fishing at the Pond
)
... etc ...
[29] => Array
(
[start] => 20101125T150000Z
[event] => Football Match
)
)
I have the following array which is made up of a datetime and an event. I am looking to return the next event from today's date. Eg: If today's date is 2010-11-19 then 'Football Match' is returned.
What is the best way to achieve this result?
Many thanks.
Array(
[1] => Array
(
[start] => 20101113T100000Z
[event] => Fishing at the Pond
)
... etc ...
[29] => Array
(
[start] => 20101125T150000Z
[event] => Football Match
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不将日期时间作为数组的键?我认为这会简单得多,因为你只有 2 个值。
然后使用 foreach,用今天的日期测试每个值,并在找到所需内容时停止。
Why don't you put your datetime as your array's key ? Imo that would be much simpler, as you only have 2 values.
Then with a foreach, you test each value with today's date, and stop when you found what you want.