所以我有以下数组($lifeSpanArray
),我正在寻找计算两个日期之间的平均间隔。
到目前为止我所拥有的,但我认为我的想法有点错误:
<?php
foreach ($lifeSpanArray as $key) {
$newTimeAdd = new DateTime($key["timeAdded"]);
$newTimeRead = new DateTime($key["timeRead"]);
$interval = $newTimeAdd->diff($newTimeRead);
var_dump($interval);
}
?>
哪个输出:
Array
(
[0] => Array
(
[timeAdded] => 07/15/2014
[timeRead] => 07/15/2014
)
[1] => Array
(
[timeAdded] => 07/14/2014
[timeRead] => 07/14/2014
)
[2] => Array
(
[timeAdded] => 07/13/2014
[timeRead] => 07/15/2014
)
[3] => Array
(
[timeAdded] => 07/13/2014
[timeRead] => 07/13/2014
)
[4] => Array
(
[timeAdded] => 07/12/2014
[timeRead] => 07/12/2014
)
[5] => Array
(
[timeAdded] => 07/12/2014
[timeRead] => 07/12/2014
)
[6] => Array
(
[timeAdded] => 07/12/2014
[timeRead] => 07/12/2014
)
[7] => Array
(
[timeAdded] => 07/12/2014
[timeRead] => 07/12/2014
)
[8] => Array
(
[timeAdded] => 07/12/2014
[timeRead] => 07/12/2014
)
[9] => Array
(
[timeAdded] => 07/11/2014
[timeRead] => 07/11/2014
)
[10] => Array
(
[timeAdded] => 07/11/2014
[timeRead] => 07/11/2014
)
[11] => Array
(
[timeAdded] => 07/10/2014
[timeRead] => 07/11/2014
)
[12] => Array
(
[timeAdded] => 07/10/2014
[timeRead] => 07/10/2014
)
)