sw9 Posted January 16, 2009 Share Posted January 16, 2009 Hi there, I have an associative array that holds event dates (in the form of m/d), event titles, and links to their full page display on my site. As I gather the events, I add them to the array like this: <?php array_push($dated_events, array('eventDate'=>$edate, 'eventTitle' =>$node->title, 'eventPath' =>$node->path));?> But they are all out of order (and I can't order them in my mySQL statement because I am pulling events from multiple places in multiple functions on my page). So now I want to perform a sorting function on the eventDate key/value pair of that array. I can't seem to figure out how to do this as if I just do a sort($dated_events, 'my_cmp_function') it does not do it based on date. If I run a foreach loop like <?php foreach ($dated_events as $event) { usort($event['eventDate'],'my_cmp_function'); } then I get an error that usort argument needs to be an array. But if I just do <?php foreach ($dated_events as $event) { usort($event,'my_cmp_function'); }?> it doesn't work either. Can anyone help me on this one? Thanks much in advance! Link to comment https://forums.phpfreaks.com/topic/141078-solved-sorting-question/ Share on other sites More sharing options...
Mark Baker Posted January 16, 2009 Share Posted January 16, 2009 foreach ($dated_events as $key => $row) { $eventDate[$key] = strtotime($row['eventDate']); } array_multisort($eventDate, SORT_ASC, $dated_events); Link to comment https://forums.phpfreaks.com/topic/141078-solved-sorting-question/#findComment-738382 Share on other sites More sharing options...
sw9 Posted January 16, 2009 Author Share Posted January 16, 2009 Thank you, thank you, thank you. Perfect. Link to comment https://forums.phpfreaks.com/topic/141078-solved-sorting-question/#findComment-738414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.