title: Every third element should have a date beside it
body: <p>So I have been asking a lot of array based questions as I strive to understand PHP's main source of data structure.</p>
  
  <p>I am currently working on building a class that spits out a list of artists and their songs. each third song has a date beside it. as seen in this array:</p>
  
  <pre><code>$music = array(
      'Creed' =&gt; array(
          'Human Clay' =&gt; array(
              array(
                  'title' =&gt; 'Are You Ready'
              ),
              array(
                  'title' =&gt; 'What If'
              ),
              array(
                  'title' =&gt; 'Beautiful',
                  'date' =&gt; '2012'
              ),
              array(
                  'title' =&gt; 'Say I'
              ),
              array(
                  'title' =&gt; 'Wrong Way'
              ),
              array(
                  'title' =&gt; 'Faceless Man',
                  'date' =&gt; '2013'
  
              ),
              array(
                  'title' =&gt; 'Never Die'
              ),
              array(
                  'title' =&gt; 'With Arms Wide pen'
              ),
              array(
                  'title' =&gt; 'Higher',
                  'date' =&gt; '1988'
              ),
              array(
                  'title' =&gt; 'Was Away Those Years'
              ),
              array(
                  'title' =&gt; 'Inside Us All'
              ),
              array(
                  'title' =&gt; 'Track 12',
                  'date' =&gt; '1965'
              ),
          ),
      ),
  );
  </code></pre>
  
  <p>What I wrote was the following:</p>
  
  <pre><code>class Music{
  
      protected $_music = array();
  
      protected $_html = '';
  
      public function __construct(array $music){
          $this-&gt;_music = $music;
      }
  
      public function get_music(){
          $year = '';
          $this-&gt;_html .= '&lt;d1&gt;';
  
          foreach($this-&gt;_music as $artist=&gt;$album){
              $this-&gt;_html .= '&lt;dt&gt;' . $artist . '&lt;/dt&gt;';
              foreach($album as $track=&gt;$song){
                  foreach($song as $songTitle){
                      if(isset($songTitle['date']) &amp;&amp; !empty($songTitle['date'])){
                          $year = '['.$songTitle['date'].']';
                      }
                      $this-&gt;_html .= '&lt;dd&gt;' . $songTitle['title'] . $year. '&lt;/dd&gt;';
  
                  }
              }
          }
          $this-&gt;_html .= '&lt;/d1&gt;';
  
      }
  
      public function __toString(){
          return $this-&gt;_html;
      }
  
  }
  
  $object = new Music($music);
  $object-&gt;get_music();
  
  echo $object;
  </code></pre>
  
  <p>My question is that I end up getting something back that looks like this:</p>
  
  <pre><code>Creed
      Are You Ready
      What If
      Beautiful[2012]
      Say I[2012]
      Wrong Way[2012]
      Faceless Man[2013]
      Never Die[2013]
      With Arms Wide pen[2013]
      Higher[1988]
      Was Away Those Years[1988]
      Inside Us All[1988]
      Track 12[1965]
  </code></pre>
  
  <p>As you can see almost every song has a date beside it when in the array that is not the case. My question is whats the deal? I thought in my loop I was very clear in stating if this song has a year, set it and then print it beside the song title?</p>
  
  <p>Can some one point me in the right direction please?</p>