You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But seriously, upgrade to 7 and use the spaceship operator instead.
132
+
133
+
### PHP doesn't have a shorthand for sorting by fields
134
+
When you're comparing a list of objects, you usually want to compare the same field on them repeatedly. Usually that means writing a usort function like this:
135
+
136
+
```
137
+
Sort::user($list, function (HighScore $a, HighScore $b) {
138
+
return $a->getPoints() <=> $b->getPoints();
139
+
});
140
+
```
141
+
142
+
And that's with the PHP 7 shorthand operator helping. This library offers a slightly shorter, Scala inspired version where you can just specify the function to retrieve the data for both objects.
0 commit comments