CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [PHP] usort

  1. #1
    Join Date
    Nov 2009
    Posts
    31

    [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

  2. #2
    Join Date
    Nov 2009
    Posts
    31

    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
  •  





Click Here to Expand Forum to Full Width

Featured