Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 31st, 2012  |  syntax: None  |  size: 0.47 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.     $duration = 1234567;
  3.  
  4.     $time_parts = array(
  5.         'days' => 60*60*24,
  6.         'hrs'  => 60*60,
  7.         'min'  => 60,
  8.         'sec'  => 1
  9.     );
  10.  
  11.     $total = array();
  12.  
  13.     foreach ($time_parts as $unit => $seconds) {
  14.         $total[$unit] = floor($duration/$seconds);
  15.         $duration %= $seconds;
  16.     }
  17.  
  18.     print_r($total);
  19.  
  20.     /*
  21.     Array
  22.     (
  23.         [days] => 14
  24.         [hrs] => 6
  25.         [min] => 56
  26.         [sec] => 7
  27.     )
  28.     */