process time with null value
<p>Stuck trying to figure out the best algorithm here.  I have this simple function where the input is seconds:</p>

<pre><code>function strTime($s) {
  $d = intval($s/86400);
  $s -= $d*86400;

  $h = intval($s/3600);
  $s -= $h*3600;

  $m = intval($s/60);
  $s -= $m*60;

  if ($d) $str = $d . 'day ';
  if ($h) $str .= $h . 'hr ';
  if ($m) $str .= $m . 'min ';
  if ($s) $str .= $s . 'sec';

  return $str;
}
</code></pre>

<p>I like this because it will only show what is needed.  For example if the seconds are at 3600 the output of this function will be "1 hr".</p>

<p>My issue is that in some cases the seconds will be 0 (when they start using the product).  How can I show 0 secs in those cases but in other times like the example above I don't want it to say "1 hr 0 sec".  I'm struggling to think of a way to do this.</p>
