title: Generating a PHP Multidimensional array within a foreach loop
body: <p>I'm looping through an array of days in the current month to generate another array of days that are on or after the current day. I then need to incorporate this into what I believe is a multidimensional array (haven't worked with these types of arrays before). Here's my code that generates the days of the month and compares each one to the current date to get my initial array:</p>
  
  <pre><code>// Set the default timezone
  date_default_timezone_set('Australia/Sydney');
  $today = date("j");
  $firstDayCurrentMonth = date("Y-m-01");
  
  // Get number of days in current month
  $days = date("t");
  // echo $days;
  
  // Get array of all dates in current month
  $aDates = array();
  $oStart = new DateTime($firstDayCurrentMonth);
  $oEnd = clone $oStart;
  $oEnd-&gt;add(new DateInterval("P1M"));
  
  while($oStart-&gt;getTimestamp() &lt; $oEnd-&gt;getTimestamp()) {
      $aDates[] = $oStart-&gt;format('j');
      $oStart-&gt;add(new DateInterval("P1D"));
  }                           
  
  // Setup days array
  $days = array();    
  
  // Generate $linked_days array to feed into calendar files 
  foreach($aDates as $date) {
      if($date &gt;= $today) {
          $days[] = $date;
      }                    
  }
  </code></pre>
  
  <p>This is all working well so far - I now need to incorporate this array of days into an array in this format:</p>
  
  <pre><code>array("year" =&gt; array("month" =&gt; array(days)));
  </code></pre>
  
  <p>For example for the 2nd of Dec, 2013 it would look like this:</p>
  
  <pre><code>$allDays = array("2013" =&gt; array("12" =&gt; array(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)));
  </code></pre>
  
  <p>I'm not sure how to insert my array of days into a large multidimensional array?</p>