我有这个函数,其中包含一个时间标记数组:
function TimeAgo($time, $ret = '') {
$time = time() - strtotime($time); // to get the time since that moment
$tokens = array (
'year' => 31536000,
'month' => 2592000,
'week' => 604800,
'day' => 86400,
'hour' => 3600,
'minute' => 60,
'second' => 1
);
}
我将检查$ret
是否等于数组中的一个名称(年、月等),如果是,我想将$time
转换为选定的
如何将$time
转换为其中一个代币?
我想你想要这个:
return (isset($tokens[$ret])) ? $time/$tokens[$ret] : $time;