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
【10.x】Individual wrapping in Collection::sortByMany allows sorting with multiple attributes by just an array of attributes(without direction, defaulting to asceding sort), but the spec is missing in docs (#10581)
Copy file name to clipboardExpand all lines: collections.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2437,7 +2437,31 @@ Alternatively, you may pass your own closure to determine how to sort the collec
2437
2437
]
2438
2438
*/
2439
2439
2440
-
If you would like to sort your collection by multiple attributes, you may pass an array of sort operations to the `sortBy` method. Each sort operation should be an array consisting of the attribute that you wish to sort by and the direction of the desired sort:
2440
+
If you would like to sort your collection by multiple attributes, you may pass an array of the attributes that you wish to sort by:
2441
+
2442
+
$collection = collect([
2443
+
['name' => 'Taylor Otwell', 'age' => 34],
2444
+
['name' => 'Abigail Otwell', 'age' => 30],
2445
+
['name' => 'Taylor Otwell', 'age' => 36],
2446
+
['name' => 'Abigail Otwell', 'age' => 32],
2447
+
]);
2448
+
2449
+
$sorted = $collection->sortBy(['name', 'age']);
2450
+
2451
+
$sorted->values()->all();
2452
+
2453
+
/*
2454
+
[
2455
+
['name' => 'Abigail Otwell', 'age' => 30],
2456
+
['name' => 'Abigail Otwell', 'age' => 32],
2457
+
['name' => 'Taylor Otwell', 'age' => 34],
2458
+
['name' => 'Taylor Otwell', 'age' => 36],
2459
+
]
2460
+
*/
2461
+
2462
+
2463
+
2464
+
When sorting in multiple attributes and directions, you may pass an array of sort operations to the `sortBy` method. Each sort operation should be an array consisting of the attribute that you wish to sort by and the direction of the desired sort:
0 commit comments