title: Translating a PHP function that converts seconds to human readable string
body: <p><a href="http://csl.sublevel3.org/php-secs-to-human-text/" rel="nofollow">In this website</a> I've found a function to convert seconds in an human readable format, like this:</p>
  
  <blockquote>
    <p>3 weeks, 2 days, 1 hour, 27 minutes, 52 seconds</p>
  </blockquote>
  
  <p>I want to translate it in italian, so I just translated array keys. The function now is this </p>
  
  <pre><code>function secondsToHumanReadable($secs) {
  
  $units = array(
  'settimane' =&gt; 604800,
  'giorni'    =&gt;  86400,
  'ore'       =&gt;   3600,
  'minuti'    =&gt;     60,
  'secondi'   =&gt;      1
  );
  
  foreach ( $units as &amp;$unit ) {
      $quot  = intval($secs / $unit);
      $secs -= $quot * $unit;
      $unit  = $quot;
  }
  
  return $units;
  }
  </code></pre>
  
  <p>It works pretty well, but there's a little problem: in english all the plurals ends with one letter less, but unfortunately in italian it's not the same, as you can see below.</p>
  
  <pre><code>English             Italian    
  - weeks, week       - settimane, settimana
  - days, day         - giorni, giorno
  - hours, hour       - ore, ora
  - minutes, minute   - minuti, minuto
  - seconds, second   - secondi, secondo
  </code></pre>
  
  <p>I want to find a solution to print singular keys when the values are == 1.</p>
  
  <p>I was thinking that I could merge the array with another array that have singular keys, using <a href="http://www.php.net/manual/en/function.array-combine.php" rel="nofollow">array_combine()</a>.</p>
  
  <pre><code>$singular_units = array(
  'settimana',
  'giorno',
  'ora',
  'minuto',
  'secondo'
  );
  
  print_r(array_combine( $singular_units, $units ));
  
  /* print_r:
  Array
  (
      [settimana] =&gt; 604800
      [giorno] =&gt; 86400
      [ora] =&gt; 3600
      [minuto] =&gt; 60
      [secondo] =&gt; 1
  )
  */
  </code></pre>
  
  <p>The array above is what I need, but I'm not able to use it, since I just cannot use another <code>foreach</code>.</p>
  
  <pre><code>$seconds = 12345*60; // just an example
  $units = secondsToHumanReadable($seconds);              
  $time_string = '';
  foreach ($units as $u =&gt; $v)
      if (!empty($v))
          $time_string.= $v.' '.$u.', ';
  echo substr($time_string, 0, -2);
  // 1 settimane, 1 giorni, 13 ore, 45 minuti
  // this echo is not correct :( is expected to be like this:
  // 1 settimana, 1 giorno, 13 ore, 45 minuti
  </code></pre>
  
  <p>How could I implement the singular words?</p>
  
  <p>Any help is <strong>really</strong> appreciated! Thank you so much in advance!</p>