Php 函数将秒转换为时间
我有一个包含时间标记数组的函数:Php 函数将秒转换为时间,php,Php,我有一个包含时间标记数组的函数: function TimeAgo($time, $ret = '') { $time = time() - strtotime($time); // to get the time since that moment $tokens = array ( 'year' => 31536000, 'month' => 2592000, 'week' => 604800,
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;
我想你想要这个:
return (isset($tokens[$ret])) ? $time/$tokens[$ret] : $time;
啊。。。哇!那很好。我会把它做成
!empty()
,因为它被设置为默认变量;然后需要检查$tokens['']是否已设置,是否抱歉我的错误。我想你最好使用array\u key\u exists
。。。哇!那很好。我会把它做成!empty()
,因为它被设置为默认变量;然后需要检查$tokens['']是否已设置,是否抱歉我的错误。我想你最好使用array\u key\u exists
。