Re: Sorting times
| From: | Shawn McKenzie | Date: | Sat, 14 Feb 2009 21:20:15 +0000 |
| Subject: | Re: Sorting times | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288270@lists.php.net to get a copy of this message | ||
tedd wrote:
> Hi gang:
>
> Anyone have/know a routine that will sort an array of times?
>
> For example, a function that would take an array like this:
>
> time[0] ~ '1:30pm'
> time[1] ~ '7:30am'
> time[2] ~ '12:30pm'
>
> and order it to:
>
> time[0] ~ '7:30am'
> time[1] ~ '12:30pm'
> time[2] ~ '1:30pm'
>
>
> Cheers,
>
> tedd
>
>
Not tested:
function time_sort($a, $b)
{
if (strtotime($a) == strtotime($b)) {
return 0;
}
return (strtotime($a) < strtotime($b) ? -1 : 1;
}
usort($time, "time_sort");
--
Thanks!
-Shawn
http://www.spidean.com