title: Building an array of Carbon Objects - PHP
body: <p>I'm confused trying to add an create an array of date instances with carbon. What I'm trying to achieve is an array with one carbon object for each day in between 2 dates.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>// Get oldest and newest date by sorting the array by created_at
  usort($data, function($a, $b) {
      return $a-&gt;created_at &lt;=&gt; $b-&gt;created_at;
  });
  
  $a = end($data);
  $to  = $a-&gt;created_at; //-&gt; Newest date
  $from = $data[0]-&gt;created_at; //-&gt; Oldest date
  
  // Work out the difference between to and from dates
  $carbonTO = new Carbon($to);
  $carbonFrom = new Carbon($from);
  $diff = $carbonFrom-&gt;diffInDays($carbonTO);
  
  // Write the dates to an array
  $i = 0;
  while ($diff &gt;= 0) {
      $filters[$i] = $carbonFrom-&gt;addDays($i);
      $diff--;
      $i++;
      var_dump($filters);
  }
  
  die();
  return $filters;
  </code></pre>
  
  <p>So the var_dump from within the loop echo's this:</p>
  
  <pre><code>array(1) { 
      [0]=&gt; object(Carbon\Carbon)#238 (3) { 
          ["date"]=&gt; string(26) "2016-01-17 19:04:49.000000" 
          ["timezone_type"]=&gt; int(3) 
          ["timezone"]=&gt; string(3) "UTC" 
          } 
   } 
  
  array(2) { 
      [0]=&gt; object(Carbon\Carbon)#238 (3) { 
          ["date"]=&gt; string(26) "2016-01-18 19:04:49.000000" 
          ["timezone_type"]=&gt; int(3) 
          ["timezone"]=&gt; string(3) "UTC" 
          } 
       [1]=&gt; object(Carbon\Carbon)#238 (3) { 
           ["date"]=&gt; string(26) "2016-01-18 19:04:49.000000" 
           ["timezone_type"]=&gt; int(3) 
           ["timezone"]=&gt; string(3) "UTC" 
           } 
        }
  </code></pre>
  
  <p>As you can see the second time I output the array the key of 0 has been overwritten by the newer date of 2016-01-18. Anyone have any ideas why? </p>
  
  <p>I'm running php 7.0.0 on mamp with Larvel 5.2.</p>