title: Create zero values for missing items in foreach loop
body: <p>I have an application that extracts some information from mysql between two dates and returns an associative array.  I am producing a graph with this information but have dates missing for the dates in the database that have no information to return.  I cannot fix this on the mysql side as I only have read only access to the database.</p>
  
  <p>My database method retrieves an associative array like the below:</p>
  
  <pre><code>[0] =&gt; Array
          (
              [number_of_calls] =&gt; 151
              [total_call_time] =&gt; 00:01:30
              [average_call] =&gt; 00:02:00
              [DATE(calldate)] =&gt; 2016-03-18
              [direction] =&gt; outbound
          )
  </code></pre>
  
  <p>What I am hoping to do is create a daterange from my form like below:</p>
  
  <pre><code>    //create data range array
      $begin = new DateTime( $datefrom );
      $end = new DateTime( $dateto );
      $end = $end-&gt;modify( '+1 day' );
      $interval = new DateInterval('P1D');
      $daterange = new DatePeriod($begin, $interval ,$end);
  </code></pre>
  
  <p>And then use a foreach loop to iterate through the selected dates of the daterange and pull the value from the associative array where the dates match and if not insert zero values like below:</p>
  
  <pre><code>        [number_of_calls] =&gt; 0
          [total_call_time] =&gt; 00:00:00
          [average_call] =&gt; 00:00:00
  </code></pre>
  
  <p>I also need the final array to end up in date order.  Can anybody help me with this please?</p>