Sort Object in PHP

后端 未结 10 1370
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 01:51

What is an elegant way to sort objects in PHP? I would love to accomplish something similar to this.

$sortedObjectArary = sort($unsortedObjectArray, $Object-         


        
10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 02:38

    For that compare function, you can just do:

    function cmp( $a, $b )
    { 
        return $b->weight - $a->weight;
    } 
    

提交回复
热议问题