0

这个函数让我困惑了一段时间,我只是无法让 foreach 语句工作,这两种情况都有效,因为它会显示单词TodayYesterdayyear, month, andday不会出现。

function time_decider($timestamp){

$date = date('m/d/Y', $timestamp);
$dif_date = date('m/d/Y',time() - (24 * 60 * 60));

$a = array( 12 * 30 * 24 * 60 * 60  =>  'year',
                30 * 24 * 60 * 60       =>  'month',
                24 * 60 * 60            =>  'day',
                );

switch ($date) {
    case date('m/d/Y'):
        return "Today";
        break;
    case $dif_date:
        return "Yesterday";
        break;
    default:

        foreach ($a as $secs => $str) {
            $d = $etime / $secs;
            if ($d >= 1) {
                $r = round($d);
                return $r . ' ' . $str . ($r > 1 ? 's ago' : '');
                break;
            }
        }
     }
  }
4

1 回答 1

1

在现在的函数$d中将始终为零,因为$etime未定义

于 2012-11-19T02:58:57.760 回答