0

I have an array of objects like the image given below. I would like to sort the array elements by the 'earned' key (descending order). I tried with usort but ended up with getting errors like usort expects parameter 1 to be array, object given. Cant figure out the problem.

 usort($users,function($a,$b) use ($users)
    {
        if ($a->earned == $b->earned) return 0;
        return ($a->earned < $b->earned)?-1:1;
    });
Noob Coder
  • 2,816
  • 8
  • 36
  • 61

0 Answers0