At 23:53 03.04.2003, Jonathan Pitcher said: --------------------[snip]-------------------- >This email is long I apologize for that. It is my code and then what >it returns and what I am wanting it to return. I don't think I >understand how USORT works or even if I am using the right function for >what I am looking for. --------------------[snip]--------------------
The compare callback is expected to return anything < 0 if the first value is less than the second (should sort _before_), 0 if they are identical, and > 0 if the first value is greater than the second (should sort _after_). Taking this, your comparison callback directs PHP this way: if ($A["STARTDATE"] < $B["STARTDATE"]) { return 4; } if $A starts before $B, $A is greater (after $B). if both start dates are equal, or $B starts before $A, continue. else if ($A["STARTTIME"] < $B["STARTTIME"]) { return 3; } if $A starts before $B, $A is greater (after $B). if both start times are equal, or $B starts before $A, continue. else if ($A["ENDDATE"] > $B["ENDDATE"]) { return 2; } if $A ends after $B, $A is greater (after $B). if both end dates are equal, or $A ends before $B, continue. else if ($A["ENDTIME"] > $B["ENDTIME"]) { return 1; } if $A ends after $B, $A is greater (after $B). if both end times are equal, or $A ends before $B, continue. else if ($A["STARTDATE"] > $B["STARTDATE"]) { return -4; } if $A starts after $B, $A is less (before $B). if both start dates are equal, continue. else if ($A["STARTIME"] > $B["STARTTIME"]) { return -3; } if $A starts after $B, $A is less (before $B). if both start times are equal, continue. else if ($A["ENDDATE"] < $B["ENDDATE"]) { return -2; } if $A ends before $B, $A is less (before $B). if both end dates are equal, continue. else if ($A["ENDTIME"] < $B["ENDTIME"]) { return -1; } if $A ends before $B, $A is less (before $B). if both end times are equal, continue. else { return 0; } they are identical. I believe you see where the problem is. You may express your comparison in a shorter and possibly clearer form like this (not tested but looks as if it should work): if ($A['STARTDATE'] < $B['STARTDATE']) return -1; // a starts before B elseif ($A['STARTDATE'] == $B['STARTDATE']) { // starts at the same day if ($A['STARTTIME'] < $B['STARTTIME']) return -1; // a starts before B elseif ($A['STARTTIME'] == $B['STARTTIME']) { // same start day and time // here both courses start at the same day/time, // so we need to sort them by enddate/time if ($A['ENDDATE'] < $B['ENDDATE']) return -1; // a ends before B elseif ($A['ENDDATE'] == $B['ENDDATE']) { // ends at the same day if ($A['ENDTIME'] < $B['ENDTIME']) return -1; // a ends before B elseif ($A['ENDTIME'] == $B['ENDTIME']) { // same end day and time // identical return 0; } } } } // we've tested all possibilities for A being less or equal to B // so there's only one more choice left - A is greater :) return 1; -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php