@@ -66,6 +66,7 @@ Here, you can quickly get started by becoming familiar with each and every metho
6666* Ordering
6767 * [ orderByKeys] ( #orderbykeysarray-array-mixed-keys-bool-appendunmatched--true-array )
6868 * [ sortByKeys] ( #sortbykeysarray-array-mixed-keys--null-bool-assoc--true-array )
69+ * [ sortObjects] ( #sortobjectsarray-objects-string-method-args-array )
6970* Computations
7071 * [ sum] ( #sumarray-arrays-array )
7172 * [ diffObjects] ( #diffobjectsarray-array1-array-array2-array-arrays-array )
@@ -536,6 +537,34 @@ Arr::sortByKeys(['a' => 3, 'b' => 1, 'c' => 6]) -> ['b' => 1, 'a' => 3, 'c' => 6
536537Arr::sortByKeys(['a' => 3, 'b' => 1, 'c' => 6], null, false) -> [1, 3, 6]
537538```
538539
540+ ### ` sortObjects(array $objects, string $method, ...$args): array `
541+ Sort array of objects by comparing result of supplied method name
542+
543+ ` $object1->$method(...$args) <=> $object2->$method(...$args) `
544+
545+ ``` php
546+ $object1 = new class() {
547+ function getValue() {
548+ return 1;
549+ }
550+ };
551+ $object2 = new class() {
552+ function getValue(bool $reverse = false) {
553+ return $reverse ? 1/2 : 2;
554+ }
555+ };
556+ $object3 = new class() {
557+ function getValue(bool $reverse = false) {
558+ return $reverse ? 1/3 : 3;
559+ }
560+ };
561+
562+ $array = [$object2, $object3, $object1];
563+
564+ Arr::sortObjects($array, 'getValue') -> [$object1, $object2, $object3]
565+ Arr::sortObjects($array, 'getValue', true) -> [$object3, $object2, $object1]
566+ ```
567+
539568## Computations
540569
541570### ` sum(array ...$arrays): array `
0 commit comments