本文介绍了如何以半小时为间隔进行时间排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个数组中的时间列表...
I needed a list of times like so in an array...
12am
12:30am
1:00pm
...
如何使用PHP做到这一点?
How can I do this with PHP?
推荐答案
谢谢您重新打开问题alex.
Thank-you for reopening the question alex.
这是一个应该引起函数式程序员共鸣的解决方案.
This is a solution that should resonate with functional programmers.
function halfHourTimes() {
$formatter = function ($time) {
if ($time % 3600 == 0) {
return date('ga', $time);
} else {
return date('g:ia', $time);
}
};
$halfHourSteps = range(0, 47*1800, 1800);
return array_map($formatter, $halfHourSteps);
}
这篇关于如何以半小时为间隔进行时间排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!