Re: [PHP] Re: Sorting times (SOLVED before tedds crappy SOLVED)

2009-02-17 Thread Jochem Maas
Shawn McKenzie schreef: > tedd wrote: >> At 9:56 AM +0100 2/16/09, Jochem Maas wrote: >>> for any reasonable number of items my tests show tedd's version >>> pisses on McKenzies from a great height (note that I actually >>> optimized Mckenzies variant by halfing the number of calls to >>> strtotime

Re: [PHP] Re: Sorting times (SOLVED before tedds crappy SOLVED)

2009-02-16 Thread tedd
At 9:45 AM -0600 2/16/09, Shawn McKenzie wrote: tedd wrote: At 9:56 AM +0100 2/16/09, Jochem Maas wrote: for any reasonable number of items my tests show tedd's version pisses on McKenzies from a great height (note that I actually optimized Mckenzies variant by halfing the number of calls t

Re: [PHP] Re: Sorting times (SOLVED before tedds crappy SOLVED)

2009-02-16 Thread Shawn McKenzie
tedd wrote: > At 9:56 AM +0100 2/16/09, Jochem Maas wrote: >> for any reasonable number of items my tests show tedd's version >> pisses on McKenzies from a great height (note that I actually >> optimized Mckenzies variant by halfing the number of calls to >> strtotime()). > > ROTFLOL. <-- I seld

Re: [PHP] Re: Sorting times (SOLVED before tedds crappy SOLVED)

2009-02-16 Thread tedd
At 9:56 AM +0100 2/16/09, Jochem Maas wrote: for any reasonable number of items my tests show tedd's version pisses on McKenzies from a great height (note that I actually optimized Mckenzies variant by halfing the number of calls to strtotime()). ROTFLOL. <-- I seldom say that! From a great

Re: [PHP] Re: Sorting times (SOLVED in half the time, hey tedd get your new and improved variant here)

2009-02-16 Thread Jochem Maas
German Geek schreef: > Remember we have copy-on-write in PHP. > > Beat this :P : for speed it's way faster, slight issue though, it won't give the expected output for arrays that contain the same value more than once. not difficult to fix that, below a new version of the test script with both you

Re: [PHP] Re: Sorting times (SOLVED before tedds crappy SOLVED)

2009-02-16 Thread German Geek
Remember we have copy-on-write in PHP. Beat this :P : Tim-Hinnerk Heuer http://www.ihostnz.com Fred Allen - "California is a fine place to live - if you happen to be an orange." 2009/2/16 Jochem Maas > Shawn McKenzie schreef: > > Shawn McKenzie wrote: > > ... > > >>> Not tested: > > no shit

Re: [PHP] Re: Sorting times (SOLVED before tedds crappy SOLVED)

2009-02-16 Thread Jochem Maas
Shawn McKenzie schreef: > Shawn McKenzie wrote: ... >>> Not tested: no shit. >>> function time_sort($a, $b) >>> { >>> if (strtotime($a) == strtotime($b)) { >>> return 0; >>> } >>> return (strtotime($a) < strtotime($b) ? -1 : 1; >>> } >>> >>> usort($time, "time_sort"); >>> >>

[PHP] Re: Sorting times (SOLVED before tedds crappy SOLVED)

2009-02-15 Thread Shawn McKenzie
Shawn McKenzie wrote: > Shawn McKenzie wrote: >> 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 or

Re: [PHP] Re: Sorting times

2009-02-15 Thread German Geek
Yes, you are right. Hadn't thought about that. But usort is probably better than making your own sort function because it uses the quick sort algorithm i believe which is quite efficient. That was the other suggestion... Tim-Hinnerk Heuer http://www.ihostnz.com Fred Allen - "California is a fine

Re: [PHP] Re: Sorting times

2009-02-15 Thread Mattias Thorslund
German Geek wrote: The easiest would probably to use http://nz.php.net/manual/en/function.strnatcmp.php . It would happen to sort it the right way because am is before pm ;-). Nope. Unfortunately 12 am (midnight) comes before 1 am, and 12 pm (noon) comes before 1 pm. Since you have to acco

Re: [PHP] Re: Sorting times

2009-02-15 Thread German Geek
The easiest would probably to use http://nz.php.net/manual/en/function.strnatcmp.php . It would happen to sort it the right way because am is before pm ;-). You can of course make it more challenging by converting it into a timestamp etc. That would be better if you want to sort by date as well et

[PHP] Re: Sorting times

2009-02-14 Thread Shawn McKenzie
Shawn McKenzie wrote: > 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'

[PHP] Re: Sorting times

2009-02-14 Thread Shawn McKenzie
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]