我了解日期期间如何工作,但有一个例外,是否有方法从日期期间找出有多少间隔?PHP DatePeriod()的迭代计数
因此,例如:
// define the period of the range
$period = new DatePeriod($begin, $rangeType, $end);
// iterate through the dates in range
foreach ($period as $dt) {
}
这是我想从上面的代码做什么:
echo count($period);
基本上我想知道foreach
循环将有多少时间,到头来。
请注意,'iterator_count'内部遍历所有项目来计算它们。所以如果这段时间很长,并且反复遍历它,那么可以自己进行计数,这样会更加高效。 –