Jump to content

[SOLVED] Sorting Question


sw9

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.