Jimmyt1988
Jimmyt1988

Reputation: 21156

Having issues with getting usort to work in ASC order

usort( $bla, function( $a, $b )
{
    return strcmp( $a->title, $b->title ); 
}); 

is returning my list in DESC order rather than ASC order... How would I go about tweaking this?

I tried:

usort( $bla, function( $a, $b )
{
    return ( strcmp( $a->title, $b->title ) < 0 ) ? $a->title : $b->title; 
});

Upvotes: 1

Views: 402

Answers (1)

Amber
Amber

Reputation: 527063

Just reverse the arguments to strcmp.

usort( $bla, function( $a, $b )
{
    return strcmp( $b->title, $a->title ); 
}); 

Upvotes: 3

Related Questions