最小化处理秒和分钟的函数
我可以缩短这个函数吗?
$mins = $secs - time('u');
function minutes($seconds){
return sprintf( "%2.2dm %2.2ds", floor($seconds/60),$seconds%60);}
$mins_left = minutes($mins);
echo "Resets in $mins_left.";
Can I shorten this function?
$mins = $secs - time('u');
function minutes($seconds){
return sprintf( "%2.2dm %2.2ds", floor($seconds/60),$seconds%60);}
$mins_left = minutes($mins);
echo "Resets in $mins_left.";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果对于函数,您的意思是
函数分钟($秒)
,那么,我认为您不能。如果您想缩短整个代码,那么您完全可以删除分钟
,但我不知道这是否适合您。考虑到这只是一个 sprintf,您可以将其作为宏处理...
If for function you're meaning
function minutes($seconds)
, well, I think you can't. if you want to shorten up your whole code, than you could removeminutes
at all, but I don't know if it's okay for you.Considering that's only a sprintf, you could handle it as a macro...
函数 分钟() 令人困惑。
它需要分钟数作为参数,并返回带有分钟和秒的字符串。
那么为什么在函数中使用 $seconds 呢?
The function minutes() is confusing.
It takes a number of minutes as an argument and return a string with minutes and seconds.
Why then use $seconds within the function?