-
November 29th, 2009, 09:09 AM
#1
[PHP] usort
I'm getting Warning: usort() [function.usort]: Invalid comparison function
Which points to
PHP Code:
if ($sort == "artist") usort($artistarray, "cmp_artist");
$artistarry is an array of objects which contain cmp_artist()
PHP Code:
static function cmp_artist($a, $b) { $tmp = strcasecmp($a->get_artist(),$b->get_artist()); if ($tmp) { return $tmp; } else { if($a->get_multiple() == $b->get_multiple() ) return "0"; if ($a->get_multiple() < $b->get_multiple() ) { $tmp = "-1"; } else { $tmp = "1";} return $tmp; } }
It is meant to sort the array by the artists name alphabetically, and if the artist appearance more than once the sort it them numerically based on it's multiple count. (the array is created in appearance order)
Last edited by Roguebfl; December 1st, 2009 at 03:35 AM.
Reason: correcting the sign of the test
-
December 1st, 2009, 03:30 AM
#2
Re: [PHP] usort
It was resolved via
PHP Code:
if ($sort == "artist") usort($artistarray, array("RefItem","cmp_artist"));
Though I could not find any documentation on why that was meant to work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|