Question

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; 
});
Was it helpful?

Solution

Just reverse the arguments to strcmp.

usort( $bla, function( $a, $b )
{
    return strcmp( $b->title, $a->title ); 
}); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top