sort an array of objects
Posted: Tue Mar 09, 2004 1:05 am
I have EmailMsg objects which contain info such as "subject" and "sent_date".
I'm creating arrays containing all the EmailMsg objects read from the database.
I merge two arrays of 2 different sets of email message objects (yes, it's weird...but that's how it has to work for this application):
I can then print a list of all messages with:
How would I re-sort the "aAllMessages" array so that all the elements (EmailMsg objects) are sorted in order of their respective sent_dates, thereby making my list print out in the correctly-sorted order?
I'm creating arrays containing all the EmailMsg objects read from the database.
I merge two arrays of 2 different sets of email message objects (yes, it's weird...but that's how it has to work for this application):
Code: Select all
$aAllMessages = array_merge($aSomeMessages,$aOtherMessages);Code: Select all
foreach ($aAllMessages as $msg) {
print "Message [".$msg->subject."] was sent on ".$msg->sent_date."<br>";
}