View difference between Paste ID: zW0n7gjS and ck2Nkpw5
SHOW: | | - or go back to the newest paste.
1
<?php
2
/*---
3
  time_dif  elapsed time function
4
  SYNOPSIS elapsed_time = time_diff(time1,time2,lang)
5
  INPUT 
6
        time1          : start time; time on unix timestamp format
7
        time2          : end time; time on unix timestamp format
8
        lang (otional) : language; string 'id' bahasa indonesia, 'en' english ; default 'id'
9
  OUTPUT
10
        elapsed_time   : elapsed time between time1 and time2, string      
11
  --- */  
12
function time_diff($time1,$time2,$lang='id')
13
{
14
  $text=Array(
15
    'id'=>Array('hari','jam','menit','detik'),
16
    'en'=>Array('day[s]','hour[s]','minute[s]','second[s]')
17
    );
18
  $ret='';
19
  $tokens = Array(86400,3600,60,1);
20
  $difference = $time2 - $time1;
21
  foreach ($tokens as $id => $value) {
22-
    if ($difference < $value){ echo "1";continue;};
22+
    if ($difference < $value) continue;
23
    $numberOfUnits = floor($difference / $value);
24
    $difference %= $value;
25
    $ret.=$numberOfUnits.' '.$text[$lang][$id].' ';
26
  }
27
  return $ret;
28
}