문제

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; 
});
도움이 되었습니까?

해결책

Just reverse the arguments to strcmp.

usort( $bla, function( $a, $b )
{
    return strcmp( $b->title, $a->title ); 
}); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top