title: How to determine if each date in an array is between dates in other arrays
body: <p>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.</p>
  
  <p>I have tried foreach loops for the dates and the DatePeriod class but I couldn't get it to work.</p>
  
  <pre><code>foreach ($dates as $value) {
    foreach ($startdates as $key =&gt; $value1) {
      foreach ($enddates as $key =&gt; $value2) {
        if ($value &gt; $value1 &amp;&amp; $value &lt; $value2) {
          result[$value] = $key;
        }
      }
    }
  }
  </code></pre>
  
  <p>dates (extract) / $dates</p>
  
  <pre><code>$dates = Array ( [0] =&gt; 2011-04-11 
                  [1] =&gt; 2011-06-28 
                  [2] =&gt; 2011-09-26 
                  [3] =&gt; 2012-01-02 
                  [4] =&gt; 2012-05-12 )
  </code></pre>
  
  <p>start dates with assigned keys (extract) / $startdates</p>
  
  <pre><code>Array ( [10] =&gt; 2011-01-01 
          [20] =&gt; 2011-07-01 
          [30] =&gt; 2012-01-01 
          [40] =&gt; 2012-07-01 )
  </code></pre>
  
  <p>end dates with assigned keys (extract) / $enddates</p>
  
  <pre><code>Array ( [10] =&gt; 2011-06-30 
          [20] =&gt; 2011-12-31 
          [30] =&gt; 2012-06-30 
          [40] =&gt; 2012-12-31 )
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>Array ( [2011-04-11] =&gt; 10 
          [2011-06-28] =&gt; 10 
          [2011-09-26] =&gt; 20 
          [2012-01-02] =&gt; 30 
          [2012-05-12] =&gt; 30 )
  </code></pre>