I have an array with dates. I have to determine which dates belongs to which periods. For that purpose I have two other arrays - one with start dates and one with end dates for these periods.
I have tried foreach loops for the dates and the DatePeriod class but I couldn't get it to work.
foreach ($dates as $value) {
foreach ($startdates as $key => $value1) {
foreach ($enddates as $key => $value2) {
if ($value > $value1 && $value < $value2) {
result[$value] = $key;
}
}
}
}
dates (extract) / $dates
$dates = Array ( [0] => 2011-04-11
[1] => 2011-06-28
[2] => 2011-09-26
[3] => 2012-01-02
[4] => 2012-05-12 )
start dates with assigned keys (extract) / $startdates
Array ( [10] => 2011-01-01
[20] => 2011-07-01
[30] => 2012-01-01
[40] => 2012-07-01 )
end dates with assigned keys (extract) / $enddates
Array ( [10] => 2011-06-30
[20] => 2011-12-31
[30] => 2012-06-30
[40] => 2012-12-31 )
I would like the result to be a new array, where the dates in the $dates array becomes keys and the periods in the start- and end dates arrays becomes values like this:
Array ( [2011-04-11] => 10
[2011-06-28] => 10
[2011-09-26] => 20
[2012-01-02] => 30
[2012-05-12] => 30 )