0

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.";
homework
  • 4,987
  • 11
  • 40
  • 50
  • 1
    "Unnecessary coding tends to give me headaches" Unnecessary comments that detract from the essential question give me headaches. I think it helps to focus on the question without distracting blather. – S.Lott Oct 03 '09 at 23:59
  • 1
    Take two aspirin and lie down. – pavium Oct 04 '09 at 00:00
  • 4
    It's really confusing that you pass a parameter called mins into a function and then refer to it as seconds. – John La Rooy Oct 04 '09 at 00:05
  • @Joey: I care about a clear long-term, enduring, persistent question and a crisp, precise answer. Personal fluff isn't part of of long-term question that everyone can benefit from. It's only a "simple question" when you make it simple. You edit focuses on the question, which is what matters here. – S.Lott Oct 04 '09 at 01:44

2 Answers2

2

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
  • 410
  • 3
  • 7
2

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
  • 14,808
  • 4
  • 33
  • 50