This function has been puzzling me for some time now, I just cannot get the foreach statement to work, both of the cases work, because it'll show the words Today
and Yesterday
but the year
, month
, and day
won't show up.
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;
}
}
}
}
在现在的函数中,由于未定义$etime
,因此$d
始终为零
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.