_
_ Handy PHP
_
_
Tutorials, Scripts, Information And Other Resources arrow Forum
Friday, 21 November 2008
_

Refer A Friend using Revolution Money Exchange
Resource Menu
Handy PHP Store
Free Domain Name
PHP Functions
PHP Downloads
PHP Newsfeeds
PHP Tutorials
Webmaster Tools
User Login
TalkPHP
Get friendly help with your PHP problems for free.
www.talkphp.com
The PHP Resource Index
Handy PHP
Free PHP Help!

FireBoard
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Array Sort By Day (2 viewing) (2) Guests
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Array Sort By Day
#8
vujsa (Admin)
Admin
Posts: 141
graph
User Online Now Click here to see the profile of this user
Array Sort By Day 2 Years ago Karma: 4  
This topic is for the discussion of the Handy PHP function Array Sort By Day.

Please keep the discussion related to this function.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#337
jlhaslip (User)
Fresh Boarder
Posts: 1
graphgraph
User Offline Click here to see the profile of this user
Re:Array Sort By Day 2 Months, 3 Weeks ago Karma: 0  
Hello Vujsa, long time no see...

Thanks for the insight into this sorting problem.
Would you recommend using a similar approach to sorting by Month?
Could the function work recursively to sort by Month and date within a month?
Or one function for month, another for weekday and another for date?

Data Samples:

sunday_dec_12.txt or nov_1_monday.txt

{think full calendar date sorting given an alpha weekday and month}
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#340
vujsa (Admin)
Admin
Posts: 141
graph
User Online Now Click here to see the profile of this user
Re:Array Sort By Day 2 Months, 2 Weeks ago Karma: 4  
Hello jlhaslip ,

This same approach would work for months or days. Basically, the way the function works now this is what happens:
your string might look like this "wednesday_m234.jpg" but the sort function reads it like "3_m234.jpg".
While it doesn't output the 3 instead of the wednesday, it knows that they are the same.
As a result, wednesday_m250.jpg would be ordered after wednesday_m234.jpg becasue, the sort function will just look to the next character to determine if it is before or after the other string.

So, you could change the function to use month names instead of weekday names.
Like so:
$search_strings = array("Sunday","Sun","Su","Monday","Mon","Mo","Tuesday","Tues","Tue","Tu","Wednesday","Wed","We","Thursday","Thurs","Thur","Thu","Th","Friday","Fri","Fr","Saturday","Sat","Sa" );
$replace_string = array('0','0','0','1','1','1','2','2','2','2','3','3','3','4','4','4','4','4','5','5','5','6','6','6' );


to this:

$search_strings = array("January", "Jan", "February", "Feb", "March", "Mar", "April", "Apr", "May", "June", "Jun", "July", "Jul", "August", "Aug", "September", "Sept", "Sep", "October", "Oct", "November", "Nov", "December", "Dec" );
$replace_string = array('901','901','902','902','903','903','904','904','905','906','906','907','907','908','908','909','909','909','910','910','911','911','912','912' );

That would change the ArraySortByDay function to sort by Month names instead.

It is also possible to do both at the same time! Just combine the old and new arrays instead of replacing the old one.

There are limitations to such a method. For example in this is how this list would be sorted.
Monday_December_28_2008
Tuesday_March_28_2000
Tuesday_March_29_1901
Tuesday_July_09_2001
Thursday_January_01_1492

As you can see, the dates will not sort as you might wish because the function would see those dates like this:
1_912_28_2008
2_903_28_2000
2_903_29_1901
2_907_09_2001
4_901_01_1492

The function is rather dumb in it's technique.

Basically, if you wanted to sort by year, then by month name, and then by weekday name, then you would have to format your strings accordingly like so:
YYYY_month_day.ext

One last thought, the years would be oldest first instead of most recent first.

It could be possible to use some date methods to reformat your strings to a more uniform system. The Reformat Date function found here: http://www.handyphp.com/index.php/PHP-Resources/Handy-PHP-Functions/reformat_date.html may help.
This function makes every attempt to read a date and convert it to the format you specify.


Hope this helps,
vujsa
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/09/07 01:08 By vujsa.
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

_
 
_
_
© 2008 Handy PHP