views:

78

answers:

2

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.";
+2  A: 

Can I shorten this function?

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 remove minutes at all, but I don't know if it's okay for you.

$mins = $secs - time('u');
$mins_left = sprintf( "%02:%02 mm:ss", floor($mins/60),$mins%60);
echo "Resets in $mins_left.";

Considering that's only a sprintf, you could handle it as a macro...

ZZambia
Anyway, $mins and $secs usage is quite disappointing :-) Unclear for a not addicted reader...
ZZambia
No idea what I was trying to do with the function. Thanks.
Homework
+2  A: 

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?

pavium