Jump to content

add 0 to a set of numbers under 10:00.00 like 09:99.99 ?


just me and php

Recommended Posts

from a table in my database i get a set of numbers like this

1.       10:06.52           

2.       10:06.93       

3.       10:10.54       

4.       11:18.65       

5.       7:52.39       

6.       8:01.51       

7.       8:37.37       

8.       8:41.01       

9.       8:43.79       

10.      9:05.03       

11.      9:17.96       

12.      9:19.29       

13.      9:23.45       

14.      9:25.03       

15.      9:25.78       

16.      9:33.70

   

but i would like it to be this

 

 

1.       07:52.39           

2.       08:01.51       

3.       08:37.37       

4.       08:41.01       

5.       08:43.79       

6.       09:05.03       

7.       09:17.96       

8.       09:19.29       

9.       09:23.45       

10.      09:25.03       

11.      09:25.78       

12.      09:33.70

13.      10:06.52           

14.      10:06.93       

15.      10:10.54       

16.      11:18.65 

 

is there a way i could add an  if (statement) or something in my  sqlquery ??to add a 0 in front of all numbers below 10:00.00       

Link to comment
Share on other sites

Try this:

<?php
function zerofill($str)
{
   list($part1,$part2) = explode(':',$str);
   return(sprintf("%02d:%s",$part1,$part2));
}
$temp = array();
$teststrs = array('7:52.39','10:10.54','11:18.65','8:01.51','8:37.37','8:41.01','9:43.79');
foreach($teststrs as $test)
     $temp[] = zerofill($test);
sort($temp);
echo '<pre>' . print_r($temp,true) . '<pre>';
?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.