Reply
Sorting all arrays inside an array together
Old 08-27-2009, 11:08 AM Sorting all arrays inside an array together
RadGH's Avatar
Skilled Talker

Posts: 62
Name: Radley
Trades: 0
I have an array laid out like this:

Code:
Filelist {
	Filename { "Test.jpg", "Image.jpg" }
	Date { "2009 08 18 00 36 36", "2009 08 25 23 10 04" }
	Ext { "jpg", "jpg" }
}
There are 10 different arrays inside the array "Filelist" which each are a different type of data. I need to sort the Date array, but arrange all other arrays afterwards, so that "Test.jpg" was created on "2009 08 18 00 36 36" even after the Date array was sorted.

I've looked through many pages on the PHP manual, searched the forum, searched google. Tried many things, but I am giving up after a few hours. I guess nobody stores data like I do. I should use objects, but it's too late now. Does anyone have any ideas? My brain can't comprehend what should be done...


To make it easier for someone to help me with this, I made a script with the very basics of my array format. It has the code you can copy/paste on the bottom, and the results on top.

http://www.radgh.com/public/

Last edited by RadGH; 08-27-2009 at 11:19 AM..
RadGH is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 08-27-2009, 04:44 PM Re: Sorting all arrays inside an array together
NullPointer's Avatar
Will Code for Food

Latest Blog Post:
Easy PHP Search with Opera
Posts: 1,070
Name: Matt
Location: Irvine, CA
Trades: 0
array_multisort should do the job:
http://us3.php.net/manual/en/functio...-multisort.php

PHP Code:
array_multisort($date$filename$ext); 
The function assumes that the first array is the one to be sorted. I imagine using objects would still be more efficient.

EDIT:

I just noticed that the dates won't sort the way you want them to if you sort them as strings. You'll need to convert them to a timestamp or some other numeric form and use that array to sort the other items:

PHP Code:
function toTimestamp($strDate)
{
     
//convert your string date to a timestamp
}

$timestamps array_map('toTimestamp'$date);
array_multisort($timestamps$date$filename$ext); 
__________________
Tinsology | How to Post Code | EverythingDev

Last edited by NullPointer; 08-27-2009 at 05:04 PM..
NullPointer is offline
Reply With Quote
View Public Profile
 
Old 08-28-2009, 07:11 AM Re: Sorting all arrays inside an array together
RadGH's Avatar
Skilled Talker

Posts: 62
Name: Radley
Trades: 0
Oh I think I understand now, it will sort the first array, and then the following arrays will be organized in the same way? It seems to work now. This will do

Thanks

The full "sort":

PHP Code:
array_multisort($filelist["ActualDate"], SORT_DESC$filelist["Filename"], $filelist["Programname"], $filelist["Extension"], $filelist["Date"], $filelist["Time"], $filelist["Size"], $filelist["URL"], $filelist["Thumb"], $filelist["Download"]); 
ActualDate is the timestamp you mentioned date("YmdHis", $Date) (YYYYMMDDHHMMSS)

Last edited by RadGH; 08-28-2009 at 07:14 AM..
RadGH is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Sorting all arrays inside an array together
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.15339 seconds with 13 queries