Php 如何在两个给定日期之间添加值

Php 如何在两个给定日期之间添加值,php,date,loops,multidimensional-array,Php,Date,Loops,Multidimensional Array,如何在两个给定日期之间添加值?我有一个数组,其中包含日期dd.mm.yyyy格式及其对应的值 阵列: Array ( [0] => Array ( [0] => 01.08.2014 [1] => 600 ) [1] => Array ( [0] => 02.08.2014 [1] => 500 ) [2] => Array ( [0] => 03.08.2014 [1] => 700 ) [3] => Array ( [0] =

如何在两个给定日期之间添加值?我有一个数组,其中包含日期dd.mm.yyyy格式及其对应的值

阵列:

Array
(
[0] => Array
(
[0] => 01.08.2014
[1] => 600
)

[1] => Array
(
[0] => 02.08.2014
[1] => 500
)

[2] => Array
(
[0] => 03.08.2014
[1] => 700
)

[3] => Array
(
[0] => 04.08.2014
[1] => 600
)

[4] => Array
(
[0] => 05.08.2014
[1] => 600
)

[5] => Array
(
[0] => 06.08.2014
[1] => 600
)

)
示例:2014年8月1日至2014年8月3日=1800。
如何使用循环来实现这一点?
我试过这个代码,但没用

$row_length = count($data);
                $sum = 0;
                for ($row = 0; $row < $row_length; $row++) {
                    $ax = $data[$row][1];
                    if ($data[$row][0] == $date1) {
                        $sum =  $ax + $sum;
                        echo $test;
                        if ($data[$row][0] == $date2) {
                            break;
                        }
                    }
                }
$row\u length=计数($data);
$sum=0;
对于($row=0;$row<$row\u length;$row++){
$ax=$data[$row][1];
如果($data[$row][0]==$date1){
$sum=$ax+$sum;
回声试验;
如果($data[$row][0]==$date2){
打破
}
}
}

我认为为这些数据找到更好的格式会让您受益匪浅

话虽如此,对于您当前的数组,我认为这会起作用,如果您将其封装在函数中,则可以传入start和end:-

$test = array();
$test[0] = array('01.08.2014', 300);
$test[1] = array('02.08.2014', 400);
$test[2] = array('03.08.2014', 800);
$test[3] = array('04.08.2014', 400);
$test[4] = array('05.08.2014', 900);
$test[5] = array('06.08.2014', 100);


$start = new DateTime('01.08.2014');
$end = new DateTime('03.08.2014');
$total = 0;

for ($i = 0; $i < count($test); $i++) {
    $date = new DateTime($test[$i][0]);
    if ($date >= $start && $date <= $end) {
        $total += $test[$i][1];
    }
}
echo $total . "\n";
$test=array();
$test[0]=阵列('01.08.2014',300);
$test[1]=阵列('02.08.2014',400);
$test[2]=阵列('03.08.2014',800);
$test[3]=阵列('04.08.2014',400);
$test[4]=阵列('2014年8月5日',900);
$test[5]=阵列('06.08.2014',100);
$start=新日期时间('01.08.2014');
$end=新日期时间(2014年8月3日);
$total=0;
对于($i=0;$i=$start&&$date请尝试以下操作:

row_length = count($data);
                $sum = 0;
                for ($row = 0; $row < $row_length; $row++) {
                    $ax = $data[$row][1];
                    if ($data[$row][0] == $date1 || $sum != 0) {
                        $sum =  $ax + $sum;
                    }
                        if ($data[$row][0] == $date2) {
                            break;
                        }
                    }
                }
行长度=计数($data);
$sum=0;
对于($row=0;$row<$row\u length;$row++){
$ax=$data[$row][1];
如果($data[$row][0]=$date1 | |$sum!=0){
$sum=$ax+$sum;
}
如果($data[$row][0]==$date2){
打破
}
}
}

这就是我所需要的!谢谢!