title: PHP: getting and adding number values outside of a loop
body: <p>I have a project here that I am working on which has a repeater cycling through an album's track listings (names &amp; lengths).</p>
  
  <p>It takes a look at minutes and seconds (written in the format of 00:03:22 for three minutes and twenty-two seconds for example). </p>
  
  <p>Now the goal of this project is to somehow be able to format this user-input number string into some sort of variable which the PHP recognizes as hours:minutes:seconds. </p>
  
  <p>Then as the foreach statement sorts through each track of the album (via the repeater) adds up each track length (in HH:MM:SS Format).</p>
  
  <p>It outputs an end total to display "38 Minutes" (or something to that effect). </p>
  
  <p>Working code sample below (Mind you, it may not be super clean &amp; there is a strong chance this code could be written way shorter), but my big issue here is getting the track totals all added together outside of the foreach loop &amp; tell the user how long the entire length of the album is.</p>
  
  <p>Thank you in advance for any help you can provide.</p>
  
  <pre><code>if( have_rows('tracks') ):
  $count = count(get_field('tracks'));
  $k = 1;
  print $count . ' Total Songs';
  $songs = get_field('tracks');
  if($songs) {
      $z = '00:00:00'; // Initial Time Setting Var
      foreach($songs as $song)
      {
          $sl = $song['length']; /Song Length
          $minutes = strstr($sl, ':', true); // Extract Minutes Value
          if ( strlen($minutes) &lt;= 2 ) { $minutes = '0' . $minutes; } // Format Minutes Value to Dual Digit If Singular
          $seconds = strstr($sl, ':'); // Extract Seconds Value
          $seconds = str_replace(':', '', $seconds); // Remove : Before Seconds
          $new_display = $minutes . ':' . $seconds; // Re-Format Minutes : Seconds
          $full_display = '00:' . $new_display; // Add Hours : Before New Time Display
          // Get Full Display Back To Seconds
          $time = explode(':', $full_display);
          $formatted_secs = ($time[0]*3600) + ($time[1]*60) + $time[2];
          // Do Some Stuff For Me
          echo '&lt;p&gt;Song'. $k .' = ' . $sl . '&lt;/p&gt;';
          echo 'Track Time For Track '. $k .' in minuntes is ' . $full_display . ' and is ' . $formatted_secs . ' seconds';
          //$z = $z+= $full_display;
          $k++; // Count
      }
      echo '&lt;br&gt;Total time is ' . $z; // Not Working Regardless
  }
  </code></pre>